bmx-ng / bmk

The enhanced BlitzMax build program.
zlib License
28 stars 13 forks source link

Disable "Overload warnings" as default ? #43

Open GWRon opened 6 years ago

GWRon commented 6 years ago

Blitzmax is intented as a "beginners friendly language". So I think it becomes a hassle to cast down things which you as "normal developer" would think should just work (even if mathematically incorrect).

Eg. I often use "sin()" + "millisecs()" to make something fade out/fade in - aka "blink". SetAlpha 0.7 + 0.3 * Sin(Millisecs()*0.25) (or so). Now "sin()" returns a double while SetAlpha expects a float. To get rid of that particular "error" (as default it is an error, not a warning...) you need to wrap either "all in all" or at least the particular sin() call to be casted into an float value.

In other cases I have a Function Draw(x:int, y:int) and call it like Draw(x + 0.5*width, y) (so "aligning" stuff). NG blames that I needed to pass an integer (which is not wrong, just "undesired"). The function definition is made this way to automatically expose the information: fractions are ignored, we draw at fixed integer points.

If you wrote all functions on your own, then this wont be an issue. I am talking about "vanilla modules". If there was a Function SetAlpha(value:float) and a Function SetAlpha(value:double) then the default user won't see the message. It would just work. (PS: you could just use the second variant and silently cast down to a float within... but maybe this is dirty).

For custom classes (done by the developer) this is a different story as the developer knows if they needed to handle "float" differently to "int" or "double". What reasons are there to not silently accept "doubles" when "floats" are requested - is it just the fact that it is no longer the same number (what is passed to the function is no longer what is received in the function) ?

I am asking as said above: it is a beginners language which allows for advanced usage. Maybe the advanced usage should be "to enable" instead of the "beginner usage".

HurryStarfish commented 6 years ago

Imo it's better to leave them on. I kinda wish the option was a switch between "error" and "warning" instead of beween "warning" and "ignore" tbh.

is it just the fact that it is no longer the same number (what is passed to the function is no longer what is received in the function)

Overloading aside, I'd say that the concern, for beginners and experts alike, is not getting what you'd expect. When you do Draw(x + 0.5*width, y), and Draw accepts Ints, then a conversion from Float to Int is done automatically. Even though you wrote x + 0.5*width, you're not getting x + 0.5*width inside the function. Instead what you're actually getting is Int(x + 0.5*width) which means that the fractional part gets sliced off. Disabling overload warnings means that the compiler will do this lossy conversion for you silently. If that's really what you wanted, then that's fine: it saved you a little bit of typing. But if you did this accidentally, you just wrote a subtle bug that can be hard to notice and even harder to locate. And especially for a beginner it can be hard to figure out why the number seems to be changing on its own; without a warning, there isn't any hint as to what could be causing it.

Essentially, this is a decision between "preventing more mistakes" and "allowing for slightly shorter code". Imo the former is preferrable, so I recommend having the warnings enabled.

GWRon commented 6 years ago

Yeah it should "warn" at least in default state (in MaxIDE the option is called "overload warnings" - which is a bit misleading).

By default I would like to see "warnings". You could also compile with a "stricter" overload-setup so it errors out on such lossy casts. And then there is the "keep silent" warning level which just does not print out things.

If doing such a thing I would not just print out "warnings" inbetween the compilation, but also when finished ("linking done").

Compilation finished. Time: A:B. X warnings, Y bla bla ...