Laying out code opinions?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
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 »

Hey, look, it still looks good. ;)
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 »

Actually, it does still look good. I guess I derped with my example.

On another note, there's a thing I read about once called Elastic Tabstops, where by there's a bit of intelligence done into how many spaces are a tab, so that you don't have to anything more than add a single tab in order to get all of your comments to align.

Of course, commenting at the end of the line is falling out of popularity anyway. I guess tabs are alright as long as they occur at the start of the line, match the nesting level, and then no more.
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 »

i admit i use pure whitespace too, tabs confuse me too much.
When in doubt i just press gg=G in vim and everything gets autoindented, afaik this can also be controlled with the "tabstop" setting.

I dont have a masterplan for aligning = or comments yet, i tend to align then but not sure if its a good idea.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Laying out code opinions?

Post by kikito »

I always indent with 2 spaces.

And I also align all the commas, colons and equal signs when it makes sense. It helps visually finding stupid bugs ("these two should be aligned and they are not ... oh, wait, I forgot an s here").

I have editor commands for transforming tabs to 2 spaces, re-indenting code selections, and aligning stuff, so I do that without thinking very much of it.
When I write def I mean function.
User avatar
Dissident
Prole
Posts: 5
Joined: Mon Jul 01, 2013 6:12 pm

Re: Laying out code opinions?

Post by Dissident »

Dissident here. I write my code with everything right up against the left side, no spaces around my equals signs, and usually no comments below the top two lines. This rarely results in write-only code, but I figure that if it does then I just need to learn the language better.

I would like to further add that I don't even use a code editor. I always get confused when people talk about their EMACS keybindings and how they couldn't live without their shortcuts in Vim, because I program just fine in Leafpad (a GTK clone of Notepad). I have tried these advanced code editors, but none of the functions they offered could get me past the fact that most of them add a linebreak to the end of the file when I don't want one there, or recolor the text in a manner that is irrelevant to my task, or just take too long to start.

Maybe I'm a bad programmer, maybe not. I can't really say, but I certainly have plenty of time to find out.
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Laying out code opinions?

Post by Xgoff »

Inny wrote: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.
i use tabs but i don't have this problem because i don't do alignment like that ;)

anyway i guess this is representative of my coding style. it's horrible
User avatar
adnzzzzZ
Party member
Posts: 305
Joined: Sun Dec 26, 2010 11:04 pm
Location: Porto Alegre, Brazil

Re: Laying out code opinions?

Post by adnzzzzZ »

Hello, Zuko here. I code with four spaces always so I can restore my honor.
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Laying out code opinions?

Post by substitute541 »

My coding style is pretty much the same as other people who use tabs.

Code: Select all

local hi = "hello"
local hello = "hi"
function foo(bar)
    print(bar)
end

local table = {
    x = 0,
    y = 0
}

-- In AS3

private var hi:String = "hello";
private var hello:String = "hi";

private function foo(bar:String) {
    trace(bar);
}
Didn't put a table variable in the AS3 one because I kinda forgot :P
Currently designing themes for WordPress.

Sometimes lurks around the forum.
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 »

substitute541 wrote:My coding style is pretty much the same as other people who use tabs.

Code: Select all

local hi = "hello"
local hello = "hi"
function foo(bar)
    print(bar)
end

local table = {
    x = 0,
    y = 0
}

-- In AS3

private var hi:String = "hello";
private var hello:String = "hi";

private function foo(bar:String) {
    trace(bar);
}
Didn't put a table variable in the AS3 one because I kinda forgot :P
I don't use AS3 very often, but when I do my style is the same as yours. Same goes for Java, C++, etc(though I never use C++, I might try to get back into it again :P).

What theme's do people use as well, and text editors? Just another curiosity thing! I use SublimeText2(I'm hoping to buy it soon and get ST3 to support the devs) and I constantly switch between themes, but the ones I use most commonly are:

Cobalt
All Hallows Eye
Tomorrow-Night-Eighties
Tomorrow-Night-Blue
Solarized(Dark)
Expresso Libre

I like to code on dark(ish/er) colours, because coding on a white background annoys my eyes after a while. I also tend to have a darker brightness level(unless I'm debugging, then that baby goes up the full way!!). Though I do use my backlit keyboard at night. I also really, really, really, really, really, really, REALLY REALLY like blue. Like, a LOT! Any blue themes for ST2 are löved by me! :D
"In those quiet moments, you come into my mind" - Liam Reilly
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests