Laying out code opinions?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
scutheotaku
Party member
Posts: 235
Joined: Sat Dec 15, 2012 6:54 am

Re: Laying out code opinions?

Post 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 :D
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Laying out code opinions?

Post 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?
Help us help you: attach a .love.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Laying out code opinions?

Post 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. :P

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.
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: Laying out code opinions?

Post 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. :P

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 :P 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.
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Laying out code opinions?

Post by Davidobot »

scutheotaku wrote: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 :D
Doom, wonderful days of Doom. I programmed in C, so I got used to the doom-style layout. Ahhhh good old days.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
scutheotaku
Party member
Posts: 235
Joined: Sat Dec 15, 2012 6:54 am

Re: Laying out code opinions?

Post by scutheotaku »

Davidobot wrote:
scutheotaku wrote: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 :D
Doom, wonderful days of Doom. I programmed in C, so I got used to the doom-style layout. Ahhhh good old days.
+1
User avatar
vitaminx
Citizen
Posts: 95
Joined: Fri Oct 19, 2012 7:16 am
Location: international
Contact:

Re: Laying out code opinions?

Post by vitaminx »

Eamonn wrote:Maybe it's just me coming from Python, but I like 4 whitespaces :P 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.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Laying out code opinions?

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Laying out code opinions?

Post 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)
Help us help you: attach a .love.
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Laying out code opinions?

Post 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.
Last edited by Inny on Wed Jul 03, 2013 11:31 pm, edited 1 time in total.
Post Reply

Who is online

Users browsing this forum: No registered users and 230 guests