PDA

View Full Version : Coding Style Guidelines?


addingice
02-27-2013, 04:47 PM
Does the code have a coding style guidelines?

I've got a couple of weeks of relaxation time coming up and I wanted to read through the EQEmu code base to get to understand it, I was wondering if we had a code style guideline since I could slowly reformat into the code style anything I find as I go.

KLS
02-27-2013, 08:27 PM
Interesting you should ask! I've been writing some on and off for some time. Though some of the rules I want to implement are... contentious: (moving to spaces over tabs for instance) which sort of keeps me from fully committing to actually getting them out. In fact many of the stupid changes I've been making have sort of been a prelude to getting the entire source more organized and easier to work with.

So I guess the answer is technically "no but I'd really really like to soon".

c0ncrete
02-27-2013, 11:15 PM
i approve of this thread.

Drajor
02-28-2013, 01:08 AM
This would improve my quality of life.

addingice
02-28-2013, 02:24 AM
VHS was a pretty shitty standard, BETA Max was definitely better. but, and this is key, VHS was a standard!

Any standard, any standard at all, is better than no standard.

the space vs tab thing can be automated with tools so it's not important, any decision there at least can be fixed.

post what you have and we can squabble like children over them! hehe

trevius
02-28-2013, 03:07 AM
(moving to spaces over tabs for instance)

I disagree with spaces over tabs. I think it would be fine to use spaces over tabs in cases such as structs or comments, just to standardize them, but for everything else (like tabbing out functions), I think spaces would suck.

Spaces are much harder to tell if you have the correct number of them for the current line you are writing. Of course, most editors will set you at the correct place automatically, but accidentally deleting an extra space will throw off the whole block you are working on if you keep working from that line on.

All decent editors allow you to tab out blocks of code by selecting the code and hitting tab X number of times. If you try that with space, it deletes your code and replaces it with a space. Even manually cleaning up formatting with this technique is much easier than doing it line by line with spaces.

If you are writing a new line of code and at the beginning of the line, you can hit tab a few times to put your code's start at the right position, but spaces would be a lot more. That is assuming you mean using multiple spaces in place of each tab. If planning to use a single space in place of each tab, that would just make it that much harder to read the format IMO.

Tabbing allows for easier movement around the source. I am sure there are alternatives to get around quickly, but tabs keep it nice and simple.

The only advantage I am aware of that spaces give over tabs is that all editors will display them the same so everything will line up no matter what you are using to view/edit the source. This is nice, but I think the benefits of tabs far outweighs a few comments (or whatever) not lining up. Maybe I am missing something?

I should have mentioned this in IRC when it was discussed a while back, but by the time I saw it the conversation had moved on and I forgot to get back to it.

Of course, it isn't my call and I am sure everyone can get by with whichever path is chosen. I just prefer stuff being easier/faster vs. lining up 100% of the time in every possible view. It will be great to have set standards for the project though. Many people are used to different styles and there is quite a mix in the source. At least with standards, some real formatting cleanup can be done throughout the source and not have people cleaning it up in their own way :)

demonstar55
02-28-2013, 03:26 AM
Yeah, but all editors can be set up to have the tab key insert spaces. (all as in all but maybe notepad ...)

Drajor
02-28-2013, 03:44 AM
IMHO one person should decide on the standard. Maybe this person can consult the other core devs about the decision privately. Allowing 'discussion' openly on this will just cause religious-like debate and waste time.

Any (commercial) software developers here that have joined an established company will most likely all have a similar story. They are handed the coding standard and expected to write code which conforms to it. End of story.

trevius
02-28-2013, 03:59 AM
Yeah, but all editors can be set up to have the tab key insert spaces. (all as in all but maybe notepad ...)

That would help with some of the inconvenience of using spaces over tabs, but can you also configure them to backspace to delete a tab worth of spaces in a single button press? My carpal tunnel is bad enough that I try to keep things as minimal as possible when I can.

Pretty simple change to switch tabs to use space for Notepad++ here:
http://stackoverflow.com/questions/455037/notepad-tabs-to-spaces

Either way, I like it when stuff works out of the box without requiring configuring stuff like editors to simplify things. No doubt people will be coding without awareness of that setting and it would be harder on them. Even if it is a simple configuration change, I think no change required is still best.

KLS
02-28-2013, 09:35 AM
Decrease indent by a tab worth of spaces on any Windows editor worth something: shift+tab.

Pretty sure Vim has a way to decrease indent too but I don't use it enough to know how offhand.

Kayen
02-28-2013, 08:56 PM
Any (commercial) software developers here that have joined an established company will most likely all have a similar story. They are handed the coding standard and expected to write code which conforms to it. End of story.

This not a company though, it is a handful of people developing the source in their limited spare time. Making the process more burdensome may raise the level entry for new contributors and discourage others.

demonstar55
02-28-2013, 09:34 PM
This not a company though, it is a handful of people developing the source in their limited spare time. Making the process more burdensome may raise the level entry for new contributors and discourage others.

But standardizing things can help with maintenance by the other devs

lerxst2112
02-28-2013, 09:49 PM
Changing from tabs to spaces or the reverse can be a lot of fun with merges if your preferred diff program doesn't properly ignore whitespace/line endings.

http://www.hanselman.com/blog/YoureJustAnotherCarriageReturnLineFeedInTheWall.as px


The best standards are simple and lightweight, otherwise people just won't follow them, even at a professional job. Most of the ones I've written are 10 or fewer bullet points and all of the formatting issues are things that you can easily do with astyle or another formatting utility so that even if people prefer to work a different way they can easily make their code conformant before they check it in.

My personal preference has always been to use 4 spaces for an indent, but I'm fine with tabs too. In fact, tabs might be better for those mildly insane individuals that like 2 character indents, or the ones that were dropped on their heads repeatedly as children that use proportional fonts.

c0ncrete
02-28-2013, 10:45 PM
hah. i just got through trying the 2 character indentation after looking at google's style guide. i had to take a shower afterwards.

wolfwalkereci
02-28-2013, 10:55 PM
hah. i just got through trying the 2 character indentation after looking at google's style guide. i had to take a shower afterwards.

Lol man that cracked me up.
I support the idea of any standard the senior dev's put out.

lerxst2112
02-28-2013, 10:56 PM
I worked on a project a long time ago that we licensed some code for. It was in C with 1 space indents, all uppercase where possible, and with most variable/function names being 32 characters long which was the limit of the compiler. It was the most horrible thing I'd ever seen.

Even back in the dark days of 80x50 DOS terminals I'd rather break a line in the middle than indent less.

Akkadius
02-28-2013, 10:57 PM
Changing from tabs to spaces or the reverse can be a lot of fun with merges if your preferred diff program doesn't properly ignore whitespace/line endings.

http://www.hanselman.com/blog/YoureJustAnotherCarriageReturnLineFeedInTheWall.as px


The best standards are simple and lightweight, otherwise people just won't follow them, even at a professional job. Most of the ones I've written are 10 or fewer bullet points and all of the formatting issues are things that you can easily do with astyle or another formatting utility so that even if people prefer to work a different way they can easily make their code conformant before they check it in.

My personal preference has always been to use 4 spaces for an indent, but I'm fine with tabs too. In fact, tabs might be better for those mildly insane individuals that like 2 character indents, or the ones that were dropped on their heads repeatedly as children that use proportional fonts.

You always make me laugh.

I always use tabs and never spaces, that could be false for some of my really old stuff.

There are programs or scripts that can be gone through the source that will beautify things but really there just needs to be practices defined in the Github.

It hasn't been a problem really with SVN because the individuals that could commit were already proven to have a somewhat decent methodology. If they didn't, they got torn up in IRC or on threads.

KLS has the most professional opinion as to standards and practices not only due to the massive experience on the Emulator but 4+ years of specialized computer science/programming that only seasoned the raw skill KLS had before and during.

Trevius has also policed our practices on emulator such as how Perl exported objects are named in quest:: and $entity-> objects for example. quest::allbeinglowercase() and $entity->HavingWordsCapitalized(); are just a few small examples.

Standards and guidelines aren't bad to have, but as always they have to be enforced and kept up upon and we've done a decent job of policing that amongst ourselves but it is a different story with anyone being able to fork to the Github now, so it wouldn't be a bad idea.

demonstar55
03-01-2013, 12:28 AM
Most simple indent policy would be just don't mix tabs and spaces, ever. Then a Dev can use tabs if they want or spaces. Plus it is better for tools to convert.

KLS
03-01-2013, 01:18 AM
I knew a guy in college who did 3 space indents, cause 2 was too few and 4 was too many. Hated reading his code, cause it was just utterly bizarre trying to line it up.

I don't intend to do complicated standards.
-We need to standardize our naming conventions (especially for things like files).
-Stop mixing tabs and spaces no matter which way we go.
-I'd like to limit line length to something, maybe not a hard limit and probably a bit more than 80 characters. Its just that it sucks reading lines that are 780 characters long cause someone couldn't be bothered to break a string up.
-There's a few practices with regard to the actual coding that would be nice to clarify how it should be done rather than keep answering questions or correcting people who do it wrong.

Drajor
03-01-2013, 05:49 AM
I have a suggestion which is related to standards, but not so much about syntax. I would love to see ALL embedded SQL moved to a single file and perhaps one day we could even transition into stored procedures.

trevius
03-01-2013, 06:38 AM
Thought of 1 more reason why I prefer to stick with tabs over spaces; If we move to spaces, that means I have 1 of 3 possible choices, which all kinda suck:

1. I change every other project I work on to use spaces instead of tabs, so I don't have to switch the configuration back and forth every time on my editors when changing between projects.

2. I change my editor settings each time I switch between projects and hope I don't forget and start mixing tabs and spaces by mistake.

3. I live without the editor config change to use spaces in the place of tabs and it makes coding in the emu a bit more annoying/time consuming.

Again, it is definitely not a huge issue, but trying to keep everything in mind before anything gets set in stone.

addingice
03-01-2013, 05:06 PM
I have a suggestion which is related to standards, but not so much about syntax. I would love to see ALL embedded SQL moved to a single file and perhaps one day we could even transition into stored procedures.

I agree on the moving out of inline, I personally would prefer a SQL folder where the SQL goes (maybe broken up by purpose? ,shrug> whatever, out of the inline at least).

i personally would be highly against the stored procedure bit though.

I agree entirely with this piece:

http://www.codinghorror.com/blog/2004/10/who-needs-stored-procedures-anyways.html

KLS
03-01-2013, 06:35 PM
Yeah definitely no to stored procedures, we're gonna rewrite the database system soonish though. So we can at least support prepared statements as well as potentially other backends besides MySQL if people choose. That all involves cleaning up the current mess that is our SQL though.