3 ms·
> Why would it “need to” crash? If it is easier to implement to not crash and the developer intention is clear why would you define your new programing language
by ekidd 3y ago
> Why would it “need to” crash? If it is easier to implement to not crash and the developer intention is clear why would you define your new programing language such that it “needs to crash” in this situation?
Well, let me come up with another example:
def a(x=SIZE): ...
a()
let SIZE = 16*1024
When we call a(), we need the value of SIZE to provide the a default value for x. But SIZE isn't computed yet. We could try to "hoist" SIZE, but normally that just means we have:
let SIZE = undefined
def a(x=SIZE): ...
a()
SIZE = 16*1024
And sure, you could invent a rule to "fix" this case, too. (It depends on how you implement default arguments efficiently.) But next week, you'll encounter another headache, and another. I've literally been through this a couple of times working on LISP compilers. "Executional" semantics are common in custom Lisp dialects, and it's a huge amount of work to get them right.
The price you end up paying is lower program performance and higher compiler complexity. Oh, and importantly, you normally wind up with slower load times. A compiled program is "ready to run", and can be loaded efficiently using mmap() and maybe some linking. But a program where you "execute" the top level needs to run all those top-level definitions on each load. So then you're like, "I know! I'll write a heap dumper/undumper", aka "unexec". Which will fix this problem but cause 5 more.
And so it goes. This is one of those ideas that seems clever but leads to bitter regrets, at least in high performance languages.
- krisoft 3y agoThank you for the example. > And sure, you could invent a rule to "fix" this case, too. I would just do the simple thing. If X is not already defined when it is used in the function signature I would just give a compile time error. Easy to implement for the compiler author, easy for the developer to understand and rectify. > But next week, you'll encounter another headache, and another. I believe you. I guess it is one of those things one has to see for themselves to really appreciate.