• Semicolon
    16 replies, posted
Should I place semicolon after every line of Lua code? Does it increase speed or makes anything else better, or it does nothing more than increasing file size? Currently I code in Lua without semicolon, and my code works fine.
Semicolon does not have any effect, i think. I did not experience any difference when I used it, and not. But maybe it does, since Kuro/Somescripter (maker of OpenAura) uses it all the time in his script. It's a good question though, I've wondered about this a while.
As far as i know it doesn't do anything. The only reason i use it is to stay in the habit for other languages.
[QUOTE=MayorBee;33428564]As far as i know it doesn't do anything. The only reason i use it is to stay in the habit for other languages.[/QUOTE] Exactly the reason it's there. Pure Lua itself doesn't use the semicolon for anything and thus would throw out a syntax error if it were to be placed outside of a string.
[QUOTE=Teddi Orange;33429262]Exactly the reason it's there. Pure Lua itself doesn't use the semicolon for anything and thus would throw out a syntax error if it were to be placed outside of a string.[/QUOTE] Semicolons are supported in vanilla Lua as well. But just like you said, it's purely optional and a personal choice. (But screw anyone who uses them in Lua, it doesn't belong there, just like garry's C-style additions [img]http://www.facepunch.com/fp/emoot/colbert.gif[/img])
Is semicolon required for separating functions in the same line of code, or you can separate them with spaces?
Not required at all.
I do it just because I learned other programming languages that way. It doesn't really matter. [editline]25th November 2011[/editline] I'd say that doing it is a better habit than not doing it. [editline]25th November 2011[/editline] And I think it makes the code more readable.
[QUOTE=_NewBee;33430007]I'd say that doing it is a better habit than not doing it..[/QUOTE] How about not making either of them a habit? Instead, make a habit of using the language's proper syntax.
Only reason I use it is because I use it in PHP, so it's more of a habit
[QUOTE=raBBish;33430331]How about not making either of them a habit? Instead, make a habit of using the language's proper syntax.[/QUOTE] You should find your own coding style so you can code quickly and efficient without thinking about syntax with every line you write.
[QUOTE=_NewBee;33430641]You should find your own coding style so you can code quickly and efficient without thinking about syntax with every line you write.[/QUOTE] So do you write every language with C-style syntax? If you have to think about the syntax while you're writing, you clearly don't actually know the language. I actually learn the languages I'm writing so I don't have to think about the syntax at all. The only problems I face are if I'm either only learning the language or haven't used it for a while.
[QUOTE=raBBish;33430724]So do you write every language with C-style syntax? If you have to think about the syntax while you're writing, you clearly don't actually know the language. I actually learn the languages I'm writing so I don't have to think about the syntax at all. The only problems I face are if I'm either only learning the language or haven't used it for a while.[/QUOTE] And even then once you're rolling with the language again it comes back pretty quick. I tend to find that good use of tabbing (and brackets where applicable for certain languages) can make any piece of code easily readable.
[QUOTE=raBBish;33430724]So do you write every language with C-style syntax? If you have to think about the syntax while you're writing, you clearly don't actually know the language. I actually learn the languages I'm writing so I don't have to think about the syntax at all. The only problems I face are if I'm either only learning the language or haven't used it for a while.[/QUOTE] I don't know the language? I have done GLua since 2006, I know how things work. If you do something a lot you will automatically develop these habits and your own coding style.
[QUOTE=_NewBee;33431317]I don't know the language? I have done GLua since 2006, I know how things work. If you do something a lot you will automatically develop these habits and your own coding style.[/QUOTE] Judging by your defensive answer you didn't actually read my post, so how about doing that, then continue reading this. If you still don't want to read it: I addressed your point of "using semicolons is a better habit than not using". In your counter-point you say that I have to think about the syntax every line I write. "If you have to think about the syntax while you're writing, you clearly don't actually know the language." I never said anything about your knowledge of languages. Unless you just admitted that you have to think about Lua's syntax every line you write. And my own coding style? I base it on the language's syntax. Language's syntax is always the base because it's a set of static rules the language operates by; your coding style shouldn't affect the operation of the language at all. Sure, if you find you like semicolons in Lua, go ahead and use them. But don't make it a habit because semicolons are a part of the syntax, not every language supports them. So, your first point? Why should I make using or not using semicolons a habit? If I make it a habit, I'll have trouble with languages that use different syntax. I'd much rather make an effort to learn the language's syntax and not use the language based on some arbitrary habits I have.
[QUOTE=raBBish;33431727]Judging by your defensive answer you didn't actually read my post, so how about doing that, then continue reading this. If you still don't want to read it: I addressed your point of "using semicolons is a better habit than not using". In your counter-point you say that I have to think about the syntax every line I write. "If you have to think about the syntax while you're writing, you clearly don't actually know the language." I never said anything about your knowledge of languages. Unless you just admitted that you have to think about Lua's syntax every line you write. And my own coding style? I base it on the language's syntax. Language's syntax is always the base because it's a set of static rules the language operates by; your coding style shouldn't affect the operation of the language at all. Sure, if you find you like semicolons in Lua, go ahead and use them. But don't make it a habit because semicolons are a part of the syntax, not every language supports them. So, your first point? Why should I make using or not using semicolons a habit? If I make it a habit, I'll have trouble with languages that use different syntax. I'd much rather make an effort to learn the language's syntax and not use the language based on some arbitrary habits I have.[/QUOTE] That would work if you're not going to learn any other languages.
[QUOTE=_NewBee;33432322]That would work if you're not going to learn any other languages.[/QUOTE] I have no idea which point you're addressing, so let's do it this way. Coding style: [sp]Am I only allowed to have one coding style? Languages look different and I have different ideas on what looks good for each one. I have no problems switching between languages as long as I still remember it. Lua is verbose and simple, so I use keep it that way: I don't spare whitespace and I keep my variable names clear. Ruby on the other hand is a bit more versatile, more compact and has more implicit syntax: not as much whitespace, tabs are two space, but I still use more descriptive variables because I like reading the code quickly. And so on.[/sp] Learning language's syntax: [sp]What's the problem here? I have no trouble remember the syntax for multiple languages, as long as I use them a bit. (Standard libraries are a whole different thing, though). I don't need bad habits in order to get the syntax right.[/sp]
Sorry, you need to Log In to post a reply to this thread.