Musings on style

BlitzMax Forums/BlitzMax Programming/Musings on style

Adam Novagen(Posted 2013) [#1]
I'm finally getting back into coding, after a good three or four months dealing with various familial and personal issues. Moving full into BlitzMax, no looking back, I've been wondering about something.

BlitzMax can use semicolons to indicate line breaks, even though they're optional. So, all the following are valid:

Print "Line 1"
Print "Line 2"

'...

Print "Line 1" ; Print "Line 2"

'...

Print "Line 1";
Print "Line 2";


Now, I realize that, in the third example, the semicolons are completely redundant. However, a lot of the most widespread languages outright require semicolon line termination. So, what I've been wondering is: how bad or silly of a thing would it be for me to use semicolons this way just to develop this as a habit, even though it's not at all required in BMax?


GfK(Posted 2013) [#2]
It's a bit of a pointless exercise, in my view.

I understand why you might want to get into the habit as so many other languages require it. But then, if you accidentally leave one out in Blitzmax, it won't error so you might not even notice it for months, then start obsessing over going through old code to make sure no more are missing.


therevills(Posted 2013) [#3]
Since in my full time job I mostly code in Java which requires the semicolon, sometimes when I code at home in BMax I accidently add a semicolon in the code... ;)

But its worst when I have week off from work and code exclusively in BMax to return to Java where I miss the semicolons :p

And don't even talk to me about the comment symbols... ' // /* -- Arrrgghhhh!!


Yasha(Posted 2013) [#4]
If you want to learn to code with semicolons, why not practice writing in a language that requires them..?

I'd call it poor style because it confuses BlitzMax with something else, in the same way that it would be poor style to practise your French by putting accents over random vowels in English. BlitzMax is not a language that has that rule, so all you're doing is introducing a lot of redundant statement breaks. And goodness knows *shock, horror* redundancy is the worst thing that can happen to code.


More seriously, this happens to be just about the least important thing to worry about if you plan to learn C-family languages, because it's the easiest error for the compiler to spot: it actually takes a bit of effort to write a pair of statements that would make sense without the semicolon in C, so the error being a difficult one is quite rare. Especially if you use a powerful IDE - most of them will highlight offending lines as you write. (Not to mention that while a compiler can't actually error out on something that would be legal, many of them these days are able to see unusual constructs and will "warn" you about them if they look like they'd have unintended consequences.)

The one exception to the above is JavaScript and any other languages that have "automatic semicolon insertion" (no others come to mind, I'm sure they exist though), but as long as you don't start by using those you should be fine.


Adam Novagen(Posted 2013) [#5]
Yeah, fair points all. I hadn't really considered how simple of a catch something like that would be; I guess in my head I was liking the "tech-y" look of the semicolons and trying to rationalize their use. XD

Cleared that up, thanks!


TomToad(Posted 2013) [#6]
this is also valid code
Print "Line 1" Print "Line 2"



Brucey(Posted 2013) [#7]
and this…


SuperStrict

Framework BRL.StandardIO

Global Much:Int, That:Int, In:Int, Window:Int



How Much Is That Doggie In The Window 



Function How(a:Int)
End Function

Function Is(a:Int)
End Function

Function Doggie(a:Int)
End Function

Function The(a:Int)
End Function



Yasha(Posted 2013) [#8]
Have your functions maintain a hidden stack of pushed values and currently-active operators, and you could turn that into a neat little embedded Forth-like DSL.

(Doing this is also known as Greenspunning and is generally considered a bad idea unless you have a really good reason, but it's also usually a really fun idea...)


Adam Novagen(Posted 2013) [#9]
Cor, I had no idea BMax was so open-minded with its syntax.


nitti(Posted 2013) [#10]
Coding styles are nice, especially when they are supersuperstrict, I found other languages (JavaScript, Python, C#) to be way more tight then Blitzmax with them.

For fun you ought to try out C# in VisualStudio or monodevelop for a while, the IDE complains and complains and enforces until you have it all exactly how it should be...

This has taught be to be a more precise coder, a good thing I think.

As for the ; in Blitzmax, I think it is unneeded and should thus be avoided at all times. In my opinion.


Scaremonger(Posted 2013) [#11]
If you want extreme coding style... Any of you remember this?
http://www.blitzbasic.com/Community/posts.php?topic=67848#758869

:)


Adam Novagen(Posted 2013) [#12]
If you want extreme coding style... Any of you remember this?
Huh; that thread was before my time in Max, thanks for pointing it out. Also, challenge accepted:

e=99b=0Graphics 320,200While a#<192And KeyHit(27)=0If b=0 x=MouseX()
If MouseHit(1)
b:+32*b=0DrawRect x-1,0,2,192If Abs(e-x)<5
a=0l#:+1e=Rnd(200)EndIf;EndIf;a:+1+l/25b:-1*b>0s=l;DrawRect x-4,192,8,4DrawOval e-4,a,8,8DrawText s,0,0;Flip;Cls;Wend

245 bytes, includes scoring, Esc quits, and it even has increasing difficulty. Gonna try a graphically updated version in 512 bytes tomorrow.


Scaremonger(Posted 2013) [#13]
lmao; thats cool :)