-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create gleam-for-go-users guide #321
base: main
Are you sure you want to change the base?
Conversation
This is an initial version that is mostly a copy of gleam-for-php-users.md
Made a lot of progress...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! This must have taken some time to write! Fantastic work.
I've left a bunch of small notes inline 🙏
Thank you
In Gleam, `let` and `=` can be used for pattern matching, but you'll get | ||
compile errors if there's a type mismatch, and a runtime error if there's | ||
a value mismatch. For assertions, the equivalent `let assert` keyword is | ||
preferred. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not just preferred! It's enforced. Could you rework to make it clear that let
won't cause a runtime error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to make this clear, if I have a value from Erlang that does not match the interface put on that code, and I do a let
with pattern that does not match that value it does not cause a runtime error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler won't let you match a let
pattern if it doesn't match all possible cases. let assert
will cause a runtime error if the pattern doesn't match
@gamebox are you planning on updating this PR? |
Yes, sorry I missed Louis's comments. I'll update sometime this week.
…On Sun, Apr 21, 2024 at 10:17 PM John Nguyen ***@***.***> wrote:
@gamebox <https://github.com/gamebox> are you planning on updating this
PR?
—
Reply to this email directly, view it on GitHub
<#321 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKRCT2MVMSVX5IW25S547DY6R6MVAVCNFSM6AAAAABEM7XYUGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRYGQYDSOJXGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
cheatsheets/gleam-for-go-users.md
Outdated
|
||
In Go, you can choose to not export a type and then they will be considered | ||
opaque to the user of your package. Just have the type have a lowercase | ||
identifier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be opaque from outside the package, which is the same thing as private? I might be misunderstanding
This will save some editing work, before I address the meatier comments. Co-authored-by: Louis Pilfold <[email protected]>
This should be ready for your review when you get a chance @lpil |
I'd really love to close this out, if you get a chance @lpil . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello! Sorry for the delay.
It seems that not all my comments have been addressed here. Let me know when the PR is ready
isn't it better to use the equivalent/similar example in the Unions section? |
@MiniAppleTheApple Well, there really isn't a similar approach unless you mean a struct that has a tag and then contains pointers to structs for all possible "variants" or contains all of the fields relevant to all variants. But I personally think it's more honest to say "This really isn't a thing you would do in Go". Plus, union semantics are just different then either of the two options I described above. |
All conversations are resolved, and suggestions merged. Looks like now this should be good for a final review. |
Even though there isn't a 100% similar way, you can still approximate both example code as close as possible. I will give a suggestion later. |
- [Unions](#unions) IN PROGRESS | ||
- [Opaque custom types](#opaque-custom-types) IN PROGRESS | ||
- [Modules](#modules) IN PROGRESS | ||
- [Imports](#imports) IN PROGRESS | ||
- [Named imports](#named-imports) IN PROGRESS | ||
- [Unqualified imports](#unqualified-imports) IN PROGRESS | ||
- [Architecture](#architecture) IN PROGRESS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these actually "in progress"? Or should this note be removed?
- Go is an imperative programming language, with only very limited object-oriented facilities | ||
provided. Gleam offers only functional code style, though it can appear | ||
imperative and reads easily thanks to pipes. | ||
- In Gleam, data structures are never mutated but always updated into new | ||
structures. This allows processes that fail to simply restart as there are no | ||
mutated objects that can be in an invalid state and take the whole | ||
application down (such as in languages like Ruby or Go). | ||
- Gleam offers syntax to make it easy to extract data out of custom types and | ||
update data into new copies of custom types without ever mutating variables. | ||
Go sometimes directly mutates references of simple values such as when using | ||
pointers or global variables, though this is very much not idiomatic. | ||
- Gleam allows to rebind variables freely to make it easy to update data | ||
structures by making a copy and binding it to the existing variable. | ||
- Go features a massive, powerful standard library centered around simple interfaces. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't really dot points, but paragraphs.
I would:
- Remove the dot points
- Move the last paragraph to the second paragraph so the Go and Gleam paragraphs are kept together
|
||
To iterate a few foundational differences (Go VS Gleam): | ||
|
||
1. Programming model: imperative VS functional immutable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A common Go-ism is something like:
- Declare struct
- Declare constructor
- Declare methods on struct
It would be handy to see how you'd achieve this in Gleam.
I know that for Gleam some people recommend a "context" struct that you pass in as the first argument which contains what would normally be Go struct fields: Database connections, loggers, HTTP clients etc.
This is a first draft and needs some editing and fact checking.
Closes #413