I am recently learning ‘real’ programming langauges, such as Javascript. Previously I learned a ‘fake’ simplified programming language called DM which is for making 2d ‘byond’ games, and got really good at it. The syntax for ‘DM’ is very simple, much like Python.
So I have a question about Javascript and other ‘curly bracket’ languages.
Here is some code in the standard style that people are ‘supposed’ to write their code in.
function OnGUI(){
if(GUI.Button(Rect(25,50,100,50),"Lol Button")){
print("Button pressed");
}
}
And likewise, this condensed version works:
function OnGUI(){
if(GUI.Button(Rect(25,50,100,50),"Lol Button")){
print("Button pressed");}}
But why isn’t this acceptable?
function OnGUI()
if(GUI.Button(Rect(25,50,100,50),"Lol Button"))
print("Button pressed")
I don’t understand the logic, it seems the curly braces and semicolons serve no purpose. Sure, semicolons can be used to place lots of code on 1 line, but otherwise shouldn’t the editor (or whatever) know that the line has ended?
Almost everyone tabs their code anyway, which is supposed to be for the same purpose, so isn’t having both redundant?
I’m just trying to understand this since I’m new to programming. It just seems like the curly brackets and semicolons serve no purpose most of the time. Maybe there is a good reason that I don’t yet understand. But right now they annoy me.
Not requiring brackets and semicolons would reduce that code from 91 to 86 characters, not even counting what you save from shift key presses to type curly brackets. That decreases typing time by like 6%.
Thanks.
The ‘DM’ programming language is ‘tab-based’ and doesn’t require curly brackets or semicolons (although they still work if a person chooses to use them) so I don’t understand why, if a ‘fake’ programming language could accomplish that, a ‘real’ one hasn’t?
