3 ms·
> var a : int ; // uninitialized is ok This seems like an odd choice when creating a new language. Most modern languages (C++11, Swift) have been introducing
by hellofunk 10y ago
> var a : int ; // uninitialized is ok
This seems like an odd choice when creating a new language. Most modern languages (C++11, Swift) have been introducing new declaration techniques or requiring all variables to be initialized at declaration, as this prevents a large class of bugs.
- hellofunk 10y agoI thought this was a new language. The repo history goes back at least as far as 2001.
- maxlybbert 10y agoI believe Felix has a special syntax to combine declaration and initialization (well, more like a shortcut; IIRC they have type inference for those cases). The code sample just shows that if you need to separate declaration and initialization, you can. I don't know about Felix, but even the simplest C compilers I use are able to warn me when they can't verify that a variable is initialized before first use. It's not that hard. And, no, you don't have to solve the halting problem as long as you're clear what you promise to warn about. There are cases where you can trivially prove initialization or failure to initialize. Promise to get those cases right, and to warn on anything else.
- unsignedqword 10y agoIMO lack of initialization in a language should be explicit, not implicit, e.g. DLang: import std.array : uninitializedArray; int a; /+ defaults to '0' +/ int b = void; /+ not initialized +/ bool[5] c; /+ defaults to array of 'false' +/ auto d = uninitializedArray!(bool[])(5); /+ not initialized +/
- hellofunk 10y agoI agree. In Swift, an uninitialized variable must be set to nil and have the properties of an optional for it to compile. Not a bad idea. Using 'auto' in C++ forces out uninitialized variables as well.
- doomrobo 10y agoUnintialized values are fine as long as the compiler can prove that the value is never used until it is initialized. See https://is.gd/gDJCeG https://is.gd/gDJCeG as an example. Try deleting the else block.
- hellofunk 10y agoThat's fine, and now that I think about it, in C++ just setting the flag to make all compiler warnings also errors, it too would prevent compilation (I think?).