AdeptLanguage / Adept

The Adept Programming Language
GNU General Public License v3.0
121 stars 9 forks source link

[improve] sizeof and sizeof value. #21

Closed ghost closed 4 years ago

ghost commented 4 years ago

@IsaacShelton Why complicate the use of sizeof? Why not combine sizeof and sizeof value?

I think it will be better if it'll looks like:

sizeof(value)
sizeof(type)

// or

sizeof value
sizeof type
IsaacShelton commented 4 years ago

@t0md3an

The reason why sizeof type and sizeof(value) are like that is because:

  1. I want it to be clear to the reader which operation it is.
  2. From a technical standpoint, combining them into a single version is very complex.

Take for example sizeof type. Which operation this is would be ambiguous. Is type a variable, or is type a user-defined type? In order for the compiler to figure this out, it would require several lookups (which slow down compile time) and also a partially parsed tree before the main parsing takes place. This would require two separate parsers which would be hard to guarantee the same output of. Also, since Adept doesn't care about the order in which things are declared (as long as they have different names), it makes doing something like this even harder to achieve without several hacks.

Another example of this problem is sizeof *value. Does this get the size of a pointer to type value, or does it get the size of memory referenced by value? Not only that, but as you have to determine whether the expression is a value or a type, it becomes exponentially more difficult and complicated, and it is just not worth it.

So in conclusion, although something like this might be nice to have, the ambiguity and technical problems that come with it are why I don't plan on implementing this in Adept 2.x.