By the way, it isn’t actually necessary for everything to be an object to make this work. The language just has to define 10.whatever() to be syntactic sugar for whatever(10). Some languages, like Python and Rust, have an explicit self parameter on their methods to help illustrate this.
But yeah, a bunch of languages decided to special-case their objects instead, for whatever reason.
this is very true but i gotta defend my object-oriented languages here (real object-oriented, not c+±style object-oriented). there’s a lot of way cooler stuff you can do with ruby or groovy or smalltalk that you just can’t do with rust, for example. objects aren’t special cases, the entire system is supposed to be implementable in itself. obviously the machine code itself can’t be objects but the good languages do their best to mask that.
That’s not quite right, the language has defined Int#days and 10 is actually Int(10). 10.days calls the instance method days on an instance of an Int (it has been years since I’ve used ruby so not sure if the stdlib class is actually Int)
Ah, I’m not talking about Ruby, I’m talking about language design in general.
I’m currently mostly doing Rust, so I can only really name that as an example (even though there’s very likely other languages that allow this, too), but yeah, here’s for example the 64-bit signed integer in Rust: https://doc.rust-lang.org/stable/std/primitive.i64.html
That is a primitive type, not an object, so it is exactly 64-bits in size and stored on the stack, not the heap. But as you can see in the documentation, Rust allows for associated functions anyways, like for example:
letmy_number: i64 = -3;
my_number.abs() //returns the absolute value, so 3
That’s because that last call is just syntactic sugar for calling the same function statically on the type:
By the way, it isn’t actually necessary for everything to be an object to make this work. The language just has to define
10.whatever()
to be syntactic sugar forwhatever(10)
. Some languages, like Python and Rust, have an explicitself
parameter on their methods to help illustrate this.But yeah, a bunch of languages decided to special-case their objects instead, for whatever reason.
this is very true but i gotta defend my object-oriented languages here (real object-oriented, not c+±style object-oriented). there’s a lot of way cooler stuff you can do with ruby or groovy or smalltalk that you just can’t do with rust, for example. objects aren’t special cases, the entire system is supposed to be implementable in itself. obviously the machine code itself can’t be objects but the good languages do their best to mask that.
That’s not quite right, the language has defined Int#days and 10 is actually Int(10). 10.days calls the instance method days on an instance of an Int (it has been years since I’ve used ruby so not sure if the stdlib class is actually Int)
Ah, I’m not talking about Ruby, I’m talking about language design in general.
I’m currently mostly doing Rust, so I can only really name that as an example (even though there’s very likely other languages that allow this, too), but yeah, here’s for example the 64-bit signed integer in Rust: https://doc.rust-lang.org/stable/std/primitive.i64.html
That is a primitive type, not an object, so it is exactly 64-bits in size and stored on the stack, not the heap. But as you can see in the documentation, Rust allows for associated functions anyways, like for example:
let my_number: i64 = -3; my_number.abs() //returns the absolute value, so 3
That’s because that last call is just syntactic sugar for calling the same function statically on the type:
i64::abs(my_number)