Page 2 of 3
Re: Laying out code opinions?
Posted: Sun Jun 30, 2013 12:58 am
by scutheotaku
If we're linking to different coding conventions/styles, I'm a big fan of the ones John Carmack wrote out for the Doom 3 team. While it doesn't all apply to Lua, much of it does (just as with Torvalds').
http://fd.fabiensanglard.net/doom3/Code ... ntions.pdf
(Original .doc version:
ftp://ftp.idsoftware.com/idstuff/doom3/ ... ntions.doc )
More info on that in practice here:
http://kotaku.com/5975610/the-exception ... ource-code
Then again, I'm a bit of a Carmack fanboy
Re: Laying out code opinions?
Posted: Sun Jun 30, 2013 6:04 am
by Robin
Eamonn wrote:I didn't make this thread for people to tell each other whether their style was wrong or not, I made it so I could see how the majority type their code.
Lesson learned? If you ask programmers about their opinion on anything, you'll get a holy war. So why bother?
Re: Laying out code opinions?
Posted: Sun Jun 30, 2013 9:51 am
by Plu
Robin wrote:Eamonn wrote:I didn't make this thread for people to tell each other whether their style was wrong or not, I made it so I could see how the majority type their code.
Lesson learned? If you ask programmers about their opinion on anything, you'll get a holy war. So why bother?
'cause if you're smart, you can use their holy war style posts to learn something worthwhile.
Working together and communicating are pretty crucial for anyone who wants to program in a team, so it's good to learn how others people do their stuff. And to make a few rules about it when you start up a combined project. I've really learned to appreciate using a specific style of formatting, because the one they have at my job might not be my favorite, and I do it completely different at home, but the fact that everyone in the team uses the same style makes code so much easier to read that it's totally worth it.
Re: Laying out code opinions?
Posted: Sun Jun 30, 2013 11:40 am
by Eamonn
Plu wrote:Robin wrote:Eamonn wrote:I didn't make this thread for people to tell each other whether their style was wrong or not, I made it so I could see how the majority type their code.
Lesson learned? If you ask programmers about their opinion on anything, you'll get a holy war. So why bother?
'cause if you're smart, you can use their holy war style posts to learn something worthwhile.
Working together and communicating are pretty crucial for anyone who wants to program in a team, so it's good to learn how others people do their stuff. And to make a few rules about it when you start up a combined project. I've really learned to appreciate using a specific style of formatting, because the one they have at my job might not be my favorite, and I do it completely different at home, but the fact that everyone in the team uses the same style makes code so much easier to read that it's totally worth it.
I
was working on a game in a team, but that died
People left because others fought, and it went from like 6 to 2 in a week. So it ended up I got fed up. I don't care how other people lay out their code, as long as it's indented. Maybe it's just me coming from Python, but I like 4 whitespaces
No idea why. Anything over 4 is too much IMO.
Really, the only thing you need to remember when programming is to
always indent. I spent about 2 hours indenting MBG correctly(I was using ZeroBrane that day, and it was indenting at 2 instead of 4), and so I saved it, opened it in Sublime Text and it was messed up again. I always try to keep my code indented right. It helps when debugging a
lot.
Re: Laying out code opinions?
Posted: Sun Jun 30, 2013 12:50 pm
by Davidobot
Doom, wonderful days of Doom. I programmed in C, so I got used to the doom-style layout. Ahhhh good old days.
Re: Laying out code opinions?
Posted: Sun Jun 30, 2013 3:40 pm
by scutheotaku
Davidobot wrote:
Doom, wonderful days of Doom. I programmed in C, so I got used to the doom-style layout. Ahhhh good old days.
+1
Re: Laying out code opinions?
Posted: Wed Jul 03, 2013 3:42 pm
by vitaminx
Eamonn wrote:Maybe it's just me coming from Python, but I like 4 whitespaces
No idea why. Anything over 4 is too much IMO.
Really, the only thing you need to remember when programming is to
always indent. I spent about 2 hours indenting MBG correctly(I was using ZeroBrane that day, and it was indenting at 2 instead of 4), and so I saved it, opened it in Sublime Text and it was messed up again. I always try to keep my code indented right. It helps when debugging a
lot.
Why not indent with tabs? changing your editors tab width setting is maybe easier than adding whitespaces everywhere by hand.
Re: Laying out code opinions?
Posted: Wed Jul 03, 2013 6:25 pm
by raidho36
My editor adds whitespace tabs for me when I press tab. It would also auto-ident when I press enter or use curly brackets. Benefits of whitespaces is that it doesn't explode if you decided to retype anything inline-tabbed. Also, using inline tabbing and having literal tabs is pretty much mutually exclusive anyway because with them it'll only displayed correctly on your notepad.
Re: Laying out code opinions?
Posted: Wed Jul 03, 2013 11:18 pm
by Robin
raidho36 wrote:Also, using inline tabbing and having literal tabs is pretty much mutually exclusive anyway because with them it'll only displayed correctly on your notepad.
You mean aligning? It's better to use spaces for that anyway. I don't usually align things, but when I do, this is my modus operandi:
Code: Select all
function hodor()
--->if verylongveryverylong and
--->...somethingelsethatislong then
--->--->functioncall(longargument1,
--->--->.............longargument2,
--->--->.............longargument3)
--->end
end
(---> means tab, . means space)
Re: Laying out code opinions?
Posted: Wed Jul 03, 2013 11:30 pm
by Inny
The problem with tabs is that people say "oh, just change your editor's tabstops", and then it turns out they mix & matched tabs and spaces. For instance, lets look at what robin just did, but with 8 char tabs:
Code: Select all
function hodor()
------->if verylongveryverylong and
------->...somethingelsethatislong then
------->------->functioncall(longargument1,
------->------->.............longargument2,
------->------->.............longargument3)
------->end
end
And again with 2 space tabs:
Code: Select all
function hodor()
->if verylongveryverylong and
->...somethingelsethatislong then
->->functioncall(longargument1,
->->.............longargument2,
->->.............longargument3)
->end
end
Heaven help us when tabs and spaces are used at the end of the line to align comments.