Code style guidelines and cleanup/work

Code style guidelines and cleanup/work

Postby oln » 08 Mar 2011, 20:08

I think we need to sort this out, now that we have more people interested in doing coding work on the project.

First, we need to decide on a set of coding style guidelines.
I would suggest something like the google ones: https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
or the ones used by DungeonHack: http://dungeonhack.sourceforge.net/Code_Style_Guidelines

We should work on having consistency in the code. Some of the work could probably be done using a refactoring tool.

Some specific things I suggest we should work on:
  • Try to avoid "using" statements in headers. (And preferably in source files as well unless it provides more clarity) (I know andrew has been removing some while developing)
  • Use the ogre logging function rather than using cout for all text output. Things printed on Stdout is not easily accessible in windows.
  • Make some sort of graceful exit and handle errors better when something fails to load. This will make it easier for people to see what's wrong if the game crashes.
  • Try to only include other headers in headers if it's strictly needed and can't be sorted with a forward declaration. This should speed up building.

There are probably some more things i have forgotten to mention.
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: Code style guidelines and cleanup/work

Postby andrewbuck » 08 Mar 2011, 21:56

Those both look like pretty good examples. I haven't read through them in detail but it would be good to make a wiki page something like the one on dungeon hack, in fact we may want to copy a lot of what they have as it looks pretty good.

-Buck
andrewbuck
OD Moderator
 
Posts: 563
Joined: 20 Dec 2009, 01:42

Re: Code style guidelines and cleanup/work

Postby oln » 08 Mar 2011, 22:06

Some more things:
Functions in ExampleFrameListener, especially the frameStarted function is veeeery long, it should probably be split up.
Ogre seems to be using floats, while we are using doubles numerous places. We should try to be consistent and use floats here. (Makes VC++ spit out a huge amount of warnings)
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: Code style guidelines and cleanup/work

Postby StefanP.MUC » 16 Mar 2011, 10:26

I currently work my way through the code and see what I can do for the cleanup (already began with some easy tasks as you can see in the git log).

I noticed some inconsitency with the includes. For example, thoughout the code "stdio" is included in all possible combinations:
{l Code}: {l Select All Code}
#include "stdio.h" //shouldn't be used with standard libs (they are probably never in the working dir)
#include <stdio.h> //C-compatible
#include <cstdio> //pure C++


Is this intended? If not, I can go through the code and unify all the standard library includes to the pure C++ versions.
Last edited by StefanP.MUC on 16 Mar 2011, 10:36, edited 1 time in total.
StefanP.MUC
 

Re: Code style guidelines and cleanup/work

Postby oln » 16 Mar 2011, 10:29

The
{l Code}: {l Select All Code}
#include <cstdio>

version is what should be used everywhere.
No reason to mix.
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: Code style guidelines and cleanup/work

Postby StefanP.MUC » 16 Mar 2011, 10:37

OK, then I'll make the includes constistent throughout the code.
StefanP.MUC
 

Re: Code style guidelines and cleanup/work

Postby StefanP.MUC » 16 Mar 2011, 15:36

I just took a look at the both links in the first post. They do some things slightly different. DungeonHack says "{" brackets on a new line while Google says only a space before them and they also have different meanings on indentation.
{l Code}: {l Select All Code}
function_or_loop() {
  //Google: space before { brackets and two spaces indent
}

function_or_loop()
{
    //DungeonHack: line break before { brackets and four spaces indent
}


I like the DungeonHack version more in both cases. The Google one is much more indepth howerer, but it also covers a lot of non-relevant stuff. I'll try to set up some basic guidelines for the start.
StefanP.MUC
 

Re: Code style guidelines and cleanup/work

Postby oln » 16 Mar 2011, 15:54

Yeah, they are not the same.
I also prefer the second version.
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: Code style guidelines and cleanup/work

Postby StefanP.MUC » 16 Mar 2011, 16:01

I created a first draft:
http://opendungeons.sourceforge.net/ind ... Guidelines

It would be good if some admin could install the sourcecode-addon to MediaWiki (or is it there? <source lang="cpp"></source> doesn't work however).
StefanP.MUC
 

Re: Code style guidelines and cleanup/work

Postby oln » 16 Mar 2011, 16:14

I'll try to install one, and also update mediawiki to the latest version.
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: Code style guidelines and cleanup/work

Postby StefanP.MUC » 16 Mar 2011, 17:09

Thanks, I already updated the page to use the source plugin.
This could use another background color, however, in its css file (the perchment bg plus colored text isn't very readable).
StefanP.MUC
 

Re: Code style guidelines and cleanup/work

Postby svenskmand » 16 Mar 2011, 18:36

StefanP.MUC {l Wrote}:Thanks, I already updated the page to use the source plugin.
This could use another background color, however, in its css file (the perchment bg plus colored text isn't very readable).

Use the same coloring as the text-box where you edit the wiki. The highlighting would need to fit on a dark background then, it does not now, can you choose between dark and light highlighting themes?
Jamendo.com - The best music store on the net, uses CC licenses.
User avatar
svenskmand
OD Moderator
 
Posts: 1850
Joined: 09 Dec 2009, 00:07
Location: Denmark

Re: Code style guidelines and cleanup/work

Postby Bodsda » 16 Mar 2011, 19:43

Can we not have code segments in a white backgrounded test box? I dislike the idea of reading code against strange coloured bg's. White or black would be a preference

Bodsda
User avatar
Bodsda
OD Moderator
 
Posts: 195
Joined: 18 Feb 2010, 08:19

Re: Code style guidelines and cleanup/work

Postby StefanP.MUC » 16 Mar 2011, 19:54

Yes, I also suggest white #FFFFFF background for the code boxes. The css of the sourcecode plugin for the text coloring assumes that the background is white. And a small box around the source code box would be nice.

The developers and their documentation don't need "fancy bling bling". The fancy stuff is only for the players and marketing. ;)

edit: Please have a look:
http://opendungeons.sourceforge.net/ind ... Guidelines
I just got the basic draft done. Comments and improvements are welcome. :)
StefanP.MUC
 

Re: Code style guidelines and cleanup/work

Postby svenskmand » 16 Mar 2011, 20:49

White is not an option, hurts your eyes when you read the wiki at night. Why suddenly change the style of the wiki? Having code on a parchment that is very dark, almost black will not hurt readability compared to pure black, but it looks better.
Jamendo.com - The best music store on the net, uses CC licenses.
User avatar
svenskmand
OD Moderator
 
Posts: 1850
Joined: 09 Dec 2009, 00:07
Location: Denmark

Re: Code style guidelines and cleanup/work

Postby StefanP.MUC » 16 Mar 2011, 20:55

Not change the global wiki style, only the css for the <source> tag (this is even only used on one single page, the guidelines). So only developers interested in the guidelines would notice the change. It has to be white, because the color formating of the <source> plugin uses dark greys and also black. And if we started to edit the css of the <source> tag then we wouldn't need it at all. ;)

While working on the guidelines I did set the wiki style to the Vector skin, I simply could not read the code on the perchment background (I have a slight color weakness).
(by the way, using the Vector skin did speed up the loading time for the pages enormously because the 250 KB picture isn't loaded anymore ;) )
StefanP.MUC
 

Re: Code style guidelines and cleanup/work

Postby svenskmand » 16 Mar 2011, 21:29

There must be a source code plugin that has colors that work on a black background. Which plugin did you install?

A quick Google gave this GeSHi, if we can install that I can adjust the colors so they fit with the theme, I just have to edit GeSHi.css it seems. Also we already planned light theme for the wiki, I have all tabs and stuff ready, if someone wants to set it up. They layout and style is the exact same as now, except that the parchment is light instead of dark, see the attached parchement texture.

Edit: it seems we are already using that plugin so I can try and edit MediaWiki:Geshi.css and make it fit. But we still need the darkened background in the text box, so it looks like the edit box when you edit a page. Here is a how to for changing the colors.

Edit^2: Making a MediaWiki:Geshi.css file did not seem to work or I am doing something wrong :S Any ideas?

Edit^3: Ok I found it, almost, here is the things I want to change the color of. But as far as I can see they do it from a terminal and not the MediaWiki:Geshi.css file :S, anybody knows how to do it using the css file?

Edit^4: Trying the approach then suggest on the MediaWiki wiki here, also does not do anything :S
Attachments
PergamentLight.png
Jamendo.com - The best music store on the net, uses CC licenses.
User avatar
svenskmand
OD Moderator
 
Posts: 1850
Joined: 09 Dec 2009, 00:07
Location: Denmark

Re: Code style guidelines and cleanup/work

Postby StefanP.MUC » 16 Mar 2011, 21:39

I think oln installed the same that is used on Wikipedia, too. Syntax highligthing is normally always for white backgrounds, because the highlighting should look the same in every development environment (that's the purpose of highlighting). ;)

A light gray (#DDDDDD or # EEEEEE) would probably work, too, if white is to light.
StefanP.MUC
 

Re: Code style guidelines and cleanup/work

Postby svenskmand » 16 Mar 2011, 21:52

StefanP.MUC {l Wrote}:Syntax highligthing is normally always for white backgrounds

That is wrong, just look at vim or emacs, eclipse or netbeans, they all support dark-themed code highlightning.

If you want something light, then you can just choose the light theme on the wiki (it has to be uploaded thought), I have all the pngs ready, so setting it up will not take long. Last time xapantu did it as he and I made the current theme, I did the graphics and he did the css and html coding. If you know how to do it you can set it up in like 5 mins as it is just copying the old theme and replacing the pngs. I have attached them here, but they are also in the SVN.

I will try and make the background use less space, but I will do that later as it will take some time, as I need to re-edit the svg for the theme to make it fit.
Attachments
Light.7z
(639.07 KiB) Downloaded 89 times
Jamendo.com - The best music store on the net, uses CC licenses.
User avatar
svenskmand
OD Moderator
 
Posts: 1850
Joined: 09 Dec 2009, 00:07
Location: Denmark

Re: Code style guidelines and cleanup/work

Postby svenskmand » 16 Mar 2011, 22:30

It seems GeSHi is just some general web-tool for making markup of code, i.e. not a MediaWiki extension per se there are apparently many extension for MediaWiki build around using GeSHi. So which extension are we using for the markup?
Jamendo.com - The best music store on the net, uses CC licenses.
User avatar
svenskmand
OD Moderator
 
Posts: 1850
Joined: 09 Dec 2009, 00:07
Location: Denmark

Re: Code style guidelines and cleanup/work

Postby oln » 16 Mar 2011, 22:37

SyntaxHighlight GeSHi is what I installed. You can log in via SSH and edit the stuff if you want svenskmand, or I can do it.
(https://sourceforge.net/apps/trac/sourceforge/wiki/Shell%20service - How to log in via SSH on sourceforge, alternatively using sftp may be easier)
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: Code style guidelines and cleanup/work

Postby svenskmand » 16 Mar 2011, 22:50

Is it possible to change the colors by changing the colors of keywords, comments, brackets, and so on? I think we should use an extension that supports that, then we can tweak the colors to match each skin of the wiki. Do you know if we can do that?
Jamendo.com - The best music store on the net, uses CC licenses.
User avatar
svenskmand
OD Moderator
 
Posts: 1850
Joined: 09 Dec 2009, 00:07
Location: Denmark

Re: Code style guidelines and cleanup/work

Postby oln » 16 Mar 2011, 23:07

Trying to find out how to change the styles at the moment.
Should be possible to change the syntax colours as well.
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: Code style guidelines and cleanup/work

Postby svenskmand » 17 Mar 2011, 01:37

Oln have now fixed the highlighting plugin, the colors can now be configured in MediaWiki:Geshi.css :) Oln and I have tweaked the colors a bit and they look pretty nice, although they are not tweaked to match the theme yet, but they are very readable.
Jamendo.com - The best music store on the net, uses CC licenses.
User avatar
svenskmand
OD Moderator
 
Posts: 1850
Joined: 09 Dec 2009, 00:07
Location: Denmark

Re: Code style guidelines and cleanup/work

Postby StefanP.MUC » 17 Mar 2011, 11:40

Yes, now it's better now. I'm still not sure if I'd like white background more, but as long as it's readable it's OK for me. ;)

I'm now starting to go through the code and try to change it accordingly to the style guidelines.
StefanP.MUC
 

Who is online

Users browsing this forum: No registered users and 1 guest

cron