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...
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...
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...
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...
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...
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...
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...
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 ...
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...
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 ...
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...
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...
Which is preferred
def method(self):
or
def method( self ):
With spaces in the parenthesis
...
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 ...
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
...
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...
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 ...
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...
Where can I find the most up-to-date official style conventions/guidelines (like how to properly name variables, methods, formatting, etc) for Java?
...
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...