Re:Felix: A compiled (to C++) scripting language
by doomrobo on Sunday July 10, 2016 @06:25PM
(#12067564)
Unintialized 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 as an example. Try deleting the else block.
Re:Felix: A compiled (to C++) scripting language
by hellofunk on Monday July 11, 2016 @05:34AM
(#12069896)
That'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?).
Re:Felix: A compiled (to C++) scripting language
by unsignedqword on Sunday July 10, 2016 @04:32PM
(#12067143)
IMO 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 +/
Re:Felix: A compiled (to C++) scripting language
by hellofunk on Sunday July 10, 2016 @04:41PM
(#12067175)
I 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.
Re:Felix: A compiled (to C++) scripting language
by hellofunk on Sunday July 10, 2016 @02:37PM
(#12066625)
I thought this was a new language. The repo history goes back at least as far as 2001.
Re:Felix: A compiled (to C++) scripting language
by maxlybbert on Sunday July 10, 2016 @03:04PM
(#12066745)
I 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.
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.