Language hacking: Function calls and parameters

preview_player
Показать описание


Рекомендации по теме
Комментарии
Автор

I wonder if it might be an idea for 'function(parameter_name)' to also take instead of having to do 'function(parameter_name: instance.parameter_name)'.

bigmistqke
Автор

I've been thinking about immutability a bit. I'd say object immutability and variable immutability are two orthogonal concepts.

That an object doesn't change its content doesn't have anything to do with a variable not being able to point to different objects. The number 5 is immutable; it's always five. But you can have a variable that's initialised with 5 and a constant that's defined as 5. The 5 doesn't care. And the other way round, neither the variable nor the constant care if whatever object they point to is immutable or not. Taken together, there can be:

* Mutable objects
* Immutable objects
* Mutable variables that contain mutable objects
* Immutable variables that contain mutable objects
* Mutable variables that contain immutable objects
* Immutable variables that contain immutable objects

Confusing? Indeed. That's why I'd suggest not merging the concepts. Let the programmer specify if the variable itself can change and if it can point to a mutable object independently.

However, "can point to a mutable object" needs further inspection, too. Does it mean, an object that is mutable can never be assigned? Or does it mean, no mutable operation can be done to the object when it is in that variable? To my understanding, "this object is mutable, but the following code says it won't do that to it" is a core concept of Jakt.

Also, assigning an immutable object to a variable that can contain mutable objects is a thing to think about. It seems to be a non-issue, like "I never declared I won't eat my car, why would I...it's inedible" (or in database terms: why duplicate the data?). Yet, for readability, it would make sense if that was clear when just looking at the consuming code without having to look up the class declaration. Also, the reality is that class declarations get changed over time. So a class that may be immutable in January, may become mutable in August.

The next thing is levels of mutability. What does it mean for an object to be immutable? Does it just mean that its fields cannot be changed? What if those unchangeable fields contain mutable objects? What if an unchangeable field contains an immutable object that represents the real-time clock? I'd classify as follows:

* An object is 1st class immutable if the values of its public members (i.e. public fields and public method return values) only depend on the identity of the object and (for methods) the given parameters.
* An object is 2nd class immutable if the values of its public members (i.e. public fields and public method return values) only depend on the identity of the object and (for methods) the given parameters and outside data.
* An object is 3rd class immutable if the values of its public members (i.e. public fields and public method return values) only depend on the identity of the object and (for methods) the given parameters and outside data and the values of contained data (i.e. mutable objects it holds in unchangeable fields).

Note that I anchored immutability on the public API of objects, not their side effects or internal storage. In many cases, this allows for objects that have side effects to be immutable. For example, an object that does vector transformations on 3D models can be immutable but still change data in the global profiler objects (i.e. record its runtime). Or allow methods to cache their return values (lazily compute on first use). I my eyes, this is more important than supporting 1st and 3rd class immutable objects.

By the way, it seems hard to have a compiler enforce this flavour of immutability, but compilers have come a long way in the past decades. Going through the parse tree and tagging variables with flags when they are assigned based on values used in the assignment and flags on the block the assignment happens in, as well as tagging blocks based on their conditional execution, is actually quite easy. And once that is in place, new flags can be introduced. For example, an "only for debug" flag that prevents the result of a method from accidentally depending on stuff that is flagged for debugging (who's never encountered a bug that only happens in production where debug code paths are disabled?).

(Reminder: Implicit data structures need a way of specifying immutability, too. An unchangeable variable with an immutable array of mutable objects and an unchangeable variable with a mutable array of immutable objects are somewhat different. In one case size() returns a value that's flagged "immutable", but in both cases, get() flags as "mutable".)

HenryLoenwind
Автор

For reference, rust gets around the current_module returning an immutable reference buy usually defining a method called get_x and get_x_mut. Not the most elegant, but it gets the job done.

driedurchin
Автор

I love watching these videos. Jakt seems like a really nice language. Watching you and JT create Jakt has inspired me to create a programming language as well (more of a toy transpiler).

Thanks!!

ryanolson
Автор

Andreas watching FriendlyJordies, was a crossover I never expected in a billion years!

cammo
Автор

im hyped for jakt, wpuld be cool if it started being used for things outside serenity as well

aloussase
Автор

The clincher was "Oh, it was not a big deal...". Of course it is a big deal! This is Serenity's own voice!

jowniemand
Автор

AWESOME as always. Can I ask a question? What "compile" stands for? I assume it is an alias for compileing cpp source right? Can you expand it Andreas? Thx for all!

MagiusChe
Автор

WHF. I can recomend the VSCode extension TODO Tree, it highlights TODO, FIXME and so on. And other tags can be added

DanielWayota
Автор

WHF. I get so excited when I see these videos, they are so entertaining

jasonl
Автор

Jakt seems like Coffeescript, but for C++. I love it.

bobbycomputers
Автор

Hello Andreas, what font are you using in the terminal? It's pretty cool :^)

alice-smith
Автор

Hey Andreas, you may want to run the rust compiler in release mode. Should speed up iteration quite a bit.

davidbriggs
join shbcf.ru