Small joys of programming in Odin
zannzen.com
zannzen.com
I have high expectations from Odin going forward, but there are some pain points hopefully will get resolved in the future. - The toolchain is alright at best (I know this is being worked on right now). - Discord only communication with the community. They're all very nice but sometimes I wish a lot of these discussions should be indexed by a search engine.
And they have a very polished language server https://github.com/DanielGavin/ols That helped me learn Odin in few hours only
Give it a try, you might like it!
Well, that’s incorrect: https://www.sobyte.net/post/2021-12/golang-garbage-collector...
Or maybe I misunderstand your comment?
A Review of the Odin Programming Language - https://news.ycombinator.com/item?id=32799499 - Sept 2022 (140 comments)
I like Odin - https://news.ycombinator.com/item?id=32626543 - Aug 2022 (204 comments)
Odin Programming Language - https://news.ycombinator.com/item?id=30394000 - Feb 2022 (42 comments)
Looking into Odin and Zig - https://news.ycombinator.com/item?id=28440579 - Sept 2021 (27 comments)
The Odin Programming Language - https://news.ycombinator.com/item?id=22199942 - Jan 2020 (141 comments)
The Odin Programming Language - https://news.ycombinator.com/item?id=20075638 - June 2019 (3 comments)
In 2023, tooling is at the point where RTFM is secondary for mainstream lang libraries (TFM being embedded into the editor in intelligent ways). I will not go back.
It is not just about getting a function from an object and then executing that function.
It is executing that function in the context of the object from which you get it, by utilizing the pseudo-variable "this" (or 'self' in Smalltalk) which refers to that object from which you got that function (a.k.a "method" in this case).
But definitely the ability to have editor-support for lookup of argument-types etc. is a great benefit too.
Ignoring runtime polymorphism for the moment, there's nothing special about "this" or "self". It's just another function parameter. Consider how in Python it is actually explicitly declared as a parameter in the method declaration.
Also lots of languages have syntactic sugar around the corresponding object e.g. implicitly dereference it for attribute access and method calls, or even give it exclusive(ish) properties like @ in Ruby (or straight up instance variable access in smalltalk).
Even Python treats it specially, given a method `foo`, `obj.foo` actually returns a proxy object which partially applies `foo` to `obj`. This only works on functions defined on the class object, mere callables set on the instance don't get that treatment.
The parent comment specifically said "by utilizing the pseudo-variable 'this' (or 'self' in Smalltalk)", so I was referring to that. Yes, in languages where the receiver is implicitly added to the lexical scope chain, things get a bit more complex.
> or even give it exclusive(ish) properties like @ in Ruby (or straight up instance variable access in smalltalk). Even Python treats it specially, given a method `foo`, `obj.foo` actually returns a proxy object which partially applies `foo` to `obj`. This only works on functions defined on the class object, mere callables set on the instance don't get that treatment.
Sure, there's other features that object-oriented languages tend to hang off methods too, but my point was just that from the perspective of within a method body, the receiver's mostly just another parameter. This is made explicit in some languages:
It is special in that when a method executes say in JavaScript, the 'this' has a very specific value even though you did not pass in an argument of that name nor did you ever assign a value to a local variable of that name. Depending on the language you use trying to assign to the (pseudo-) variable 'this' may or may not cause an error.
The "automatic" value 'this' has makes it special, different from other variables and arguments. That automatic value ties the method-call-syntax into the semantics of what it means to call a method as opposed to calling a free function.
This can be exemplified in JavaScript easily:
let funk = myOb.funk;
let v = myOb.funk();
let v2 = funk(); // throws error
In this case the error gets thrown if
myOb.funk internally refers to 'this'
and tries to access some field of it.
That causes an error because 'this' is
undefined inside 'funk' when it is called
as a plain function.When you call myOb.funk() there is NO error in the same case, because 'this' is then NOT undefined, its value is 'myOb'.
You can access any field of myOb inside the code of myOb.funk when you call it as myOb.funk().
That is a big semantic difference, not just "syntactic sugar".
It's just an implicit parameter named `this` whose argument happens to appear to the left of the `.` instead of after the `(`. Yes, there's a little extra work in the language to support this, but it's not particularly complex or deep semantically.
(In fact `this` is particularly semantically shallow in JavaScript because as your example notes, it's not even bound when a reference to a method is taken. In most other languages, `myOb.funk` will give you a function that partially applies `this`.)
No, method syntax is just syntax. In some languages methods are more than just syntax sugar, but there's nothing special about the syntax itself.
In JavaScript you can say:
let v = myOb.myFunk();
or you can say: let v2 = myFunk.call (myOb);
Those the two different syntaxes you can use to make a method-call. They have the same result for all arguments. So you can say one is syntactic sugar over the other. Their semantics are the same. In other words they have the exactly same meaning.BUT if you write:
let v3 = myFunk();
the result is different. And you get an error if your source-code assumes that 'this' is not undefined.That shows that the semantics of the 3rd example above is different from the semantics of the first two. In other words the semantics of a function-call and of a method-call are different. Therefore, we can say that method-call is not syntactic sugar for doing the same thing as a plain function-call.
For that to be syntactic sugar it would have to be the case that foo.bar(x, y) and bar(foo, x, y) always produce the same result for any given values of 'foo', 'x' and 'y'.
Is there a language where that is the case?
However, yes, there are languages where that's the case: https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax
I would also argue that extension methods in languages like C# and Kotlin are just sugar.
I've been using Odin for about a year now, many of the pain-points I've had have just been knowledge gaps. Odin's docs and debug info have slowly gotten better over time, and little discord-community tips here and there have made a huge difference for my quality of life.
Also for the record I just noticed I wrote @disable everywhere instead of @disabled. That's been fixed now
I'm confused about this caller_location thing in tests. It looks like you're just passing `loc = loc` a bunch of times for no good reason. Why can't the language automatically or implicitly implement that functionality? Having to write `loc = loc` at the end of every assertion just seems silly.
Totally tangential, but am I the only one that was taught to put punctuation inside of quotes and now despises that rule?
Seems more natural to have the period after the closing quote, at least in cases like this sentence of yours from above:
>I can't imagine someone named their language "of", "programming", or "in".
But I think there may be cases where period inside and before closing quote may seem better, e.g. if quoting what someone said, like a quoted sentence inside another sentence.
But I'm not an English grammar expert.
4: Small(talk), Joy, Pro(log) and D (from Odin).
The D language, that is.
I had explicitly excluded Odin above. :)
I do recommend the book.
I won't say don't read it -- it did manage to keep my interest, after all -- I just have a hard time recommending it due to the time-investment:reward ratio.
(Some stories don't even have a reveal at the ending at all)