Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Code style

Reply to topic
Author Message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14687
  • Location: London
Reply with quote
Code style
Post Posted: Wed Jun 07, 2017 7:51 am
Meka's code style is somewhat archaic, for various reasons. I often have a hard time matching the code style - would it be possible to standardise it a bit? Things like:

- Tabs vs spaces - there's a mixture, and I think not a consistent tab width
- Braces around one-line blocks
- Efforts to align variable names
- ANSI C variables-at-the-top vs. C++ declare them as you go
- snake_case vs. Camel_Snake_Case for function names

Some of these would be possible to enforce with a code formatter like Artistic Style...
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 08 Jul 2001
  • Posts: 8644
  • Location: Paris, France
Reply with quote
Post Posted: Wed Jun 07, 2017 8:43 am
Well yes the code needs some massaging (and the newer parts like debugger are generally a little more bearable).

Not sure what to tell you. In my experience this sort of thing feels annoying when you are trying to decipher code BUT the reality is that it is mostly the program architecture that's problematic and confusing, more than the actual style.

VisualAssist is great for that. If you would like to it on work we could setup a branch on the official repo for you.

I generally go and do this massaging on the go when I look and make some actual improvements to the code. AKA old code that particularly terrible is marked by its look.

Generally I would tend toward:
- Tabs vs spaces: either tab 4 or spaces, I only reluctantly switched to spaces because Github doesn't have per-repo tab settings in their web viewer.
- Braces around one-line blocks: I would remove them.
- Efforts to align variable names. I would align them for structures, not for function declarations.

- ANSI C variables-at-the-top vs. C++ declare them as you go: narrowing scope as much as possible, so declare as you go, possibly even sometimes explicitly scope. I also like to const local variables in non trivial functions to denote that they aren't going to change.

- snake_case vs. Camel_Snake_Case for function names: I would go SnakeCase for functions and snake_case or m_SnakeCase generally. I don't really remember what's the state of MEKA.

I'd spend a month to cleanup all of meka if I could afford the money to, maybe I'll make it my next pet project to test dear imgui.. Maybe I can spend a week-end trying to regularize code style.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14687
  • Location: London
Reply with quote
Post Posted: Wed Jun 07, 2017 11:44 am
I'm using ReSharper C++ these days which is mostly a superset of VA, and it seems possible to automate a lot of the changes with it. However, I'm always scared to check in a gazillion line change which is only changing style, and it mostly destroys all attempts at merging.

This sort of alignment seems archaic to me:


//-----------------------------------------------------------------------------
// Forward declaration
//-----------------------------------------------------------------------------

static int      Load_ROM_Init_Memory    ();
int             Load_ROM_File           (const char *filename_ext);
int             Load_ROM_Zipped         ();
int             Load_ROM_Main           ();
void            Load_ROM_Misc           (int reset);
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 08 Jul 2001
  • Posts: 8644
  • Location: Paris, France
Reply with quote
Post Posted: Wed Jun 07, 2017 9:21 pm
I tend to still align the return values but the right part I would remove it.
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!