coding-style

Coding Standards for pure C (not C++)

I come from a java background (from my CS classes) and a semester of C++. I am just finishing up a OpenCV project for my Co-Op that's in pure C, so I'm a bit late in asking this question. What are the design processes and coding standards for pure C? I'm familiar with object oriented programming, design and best practices. I'm jus...

Why is it bad to put a space before a semicolon?

The perlstyle pod states No space before the semicolon and I can see no reason for that. I know that in english there should not be any space before characters made of 2 parts ( like '?',';','!' ), but I don't see why this should be a rule when writing Perl code. I confess I personally use spaces before semicolons. My reason is t...

Is this good C# style?

Consider the following method signature: public static bool TryGetPolls(out List<Poll> polls, out string errorMessage) This method performs the following: accesses the database to generate a list of Poll objects. returns true if it was success and errorMessage will be an empty string returns false if it was not successful and error...

Should I use public properties and private fields or public fields for data?

In much of the code I have seen (on SO, thecodeproject.com and I tend to do this in my own code), I have seen public properties being created for every single private field that a class contains, even if they are the most basic type of get; set; like: private int myInt; public int MyInt { get { return myInt; } set { myInt = v...

What's the best way to write code, allowing that any developer can easily understand it?

Normally each person takes their own "calligraphy" to write code, however, is there a "standard" or any way that you feel clear and easy to allow the code becomes "readable" by any programmer who is using your code? Personally I use (a simple example): if (myVar == 5) { // easy to identify where the IF was launched, IMHO. } Inste...

behavior of bool with non-boolean operators

What I really want is a ||= operator. old_value = old_value || possible_new_value; old_value ||= possible_new_value; The second line is a compiler error (c++ doesn't have a ||= operator). So what are my other options? old_value += possible_new_value; old_value |= possible_new_value; While I'm on the subject how does bool behave wi...

States and controllable game objects

We are making a game with a playing character that will have several different states. In most examples I see a switch statement in the controllable charactor based on the state. Is this the standard way that things are done for most games? Or is it better to create a set of states that handle the animation and logic of that state. It se...

Is Resharper correct?

Hi I just installed Reshaper 4.5 and it has come up with the following suggestions: return this.GetRuleViolations().Count() == 0; -- REMOVE this. new string[] { this.ID.ToString(), this.Registration } -- REMOVE string, MAKE ANONYMOUS TYPE int i = Method.GetNumber(); -- REPLACE int WITH var Should I do these? I think in some cases ...

Looking for the most elegant code dispatcher

I think the problem is pretty common. You have some input string, and have to call a function depending on the content of the string. Something like a switch() for strings. Think of command line options. Currently I am using: using std::string; void Myclass::dispatch(string cmd, string args) { if (cmd == "foo") cmd_foo(arg...

Reasons to use NSString constants over enums?

I'm wondering why Apple is using (quite heavily in CoreAnimation, but elsewhere too) constants that are declared as NSString * const like for example kCAGravityTop instead of regular enums? How about type safety in this case? As I understand it, one could pass any NSString to a method expecting this constant without getting any compiler ...

Policy with catching std::bad_alloc

So I use Qt a lot with my development and love it. The usual design pattern with Qt objects is to allocate them using new. Pretty much all of the examples (especially code generated by the Qt designer) do absolutely no checking for the std::bad_alloc exception. Since the objects allocated (usually widgets and such) are small this is har...

Most elegant way to extract data from multiple lists into a new one in Java?

This may be a little subjective, but I have often found that it can be very interesting to see how other developers approach certain daily details. I have code which works like this: class A { public List<SomeType> getOneSet() { ... } public List<SomeType> getAnotherSet() { ... } } class B { public static OtherType convert...

Simple noob python style question.

Which is preferred def method(self): or def method( self ): With spaces in the parenthesis ...

How to do create_or_update in sqlobject?

I'm using SQLobject and so far was not able to find a elegant solution for "update row in the db or vreate a new one if it doesn't exist. Currently I use following somewhat convoluted code: args = dict(artnr=artnr, name=name, hersteller='?', hersteller_name='?') if cs.datamart.ArtNrNameHersteller.selectBy(artnr=artnr).count(): row ...

Tool to enforce python code style/standards

I'm trying to find a tool to check for coding style in python. For php I've seen there is the Code Sniffer, and a small perl script used by Drupal. Is there such a tool for python code? Thanks ...

What are the most commonly use web development policies in software companies?

Having the best forum website among developers, I think I will find a very good consensus of what policies and best practices make good coding. I will put some of them here, so I give the idea, but I will like to hear your opinion and the votes will probably be the judge of the best policies around. Specific Indentation for coding be...

Matrix/Vector Preference: Return copy or transform internally?

Just a quickie to get a feel for the community in general's preference: When working with objects like Vectors (mathematical, not STL) and Matrices do you prefer a library that: A) Doesn't alter the objects but returns copies instead: Vec2 Vec2::Add(float x, float y) { return Vec2(this.x + x, this.y + y); } B) Alters the objects ...

astyle formatting multiple line <<

I'm using astyle which is great for applying standard style to existing code. However I've noticed that when it comes across this: ostringstream myStream; myStream << 1 << 2; it reformats to this: ostringstream myStream; myStream << 1 << 2; Here's my options file: (version 1.23) --indent=spaces --brackets=break --indent...

Official Java Code Guidelines/Conventions

Where can I find the most up-to-date official style conventions/guidelines (like how to properly name variables, methods, formatting, etc) for Java? ...

Singular or plural for enumerations?

Do you use singular or plural for enumerations? I think i makes best sense with plural in the declaration enum Weekdays { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } ... but I think it makes more sense with singular when using the type, e.g. Weekday firstDayOfWeek = Weekday.Monday; I...