coding-style

How to remove unwanted functions from interface.

I have an interface class MyFunction. There are three functions in this class with the following signatures: virtual bool Eval(int& iReturnVal, size_t szArgumentCount, list<Param> lParameterList) = 0; virtual bool Eval(double& dReturnVal, size_t szArgumentCount, list<Param> lParameterList) = 0; virtual bool Eval(char*& zReturnVal, size_...

How do I make this code more readable?

I wrote this today and I'm ashamed. What do I need to do to make this chaotic stuff more accurate and readable amongst others? switch ((RequestReportsCalculatingStoredProcedures.RequestReportStoredProcedureType)Enum.Parse(typeof(RequestReportsCalculatingStoredProcedures.RequestReportStoredProcedureType), ihdType.Value)) { ...

Is using prototypes to declare array reference context on subroutine args a Good Thing in Perl?

In the linked SO answer, Eric illustrates a way to call a subroutine, which accepts arrays by reference as arguments, and use the prototypes to allow the caller code to pass the array names without using reference operator \@; the way built-ins like push @array, $value do. # Original code: sub Hello { my ($x_ref, $y_ref) = @_; ...} Hell...

How did the convention of not puttting any whitespace in Obj-C method declarations come about?

How did it become convention that there is no whitespace in the declaration of a method? -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath It seems like everyone does it, 90% of the examples I see, the generated templates, other people's code, etc., etc. I suspect it's just another vi/e...

What are the good programming practises in C# to make code more self-explanatory?

I think making code self-explanatory, without need for comments all around the place, is a big advantage. But could you suggest methods and techniques how to reduce the amount of code, make it more readable and understandable. Also what do you think are the good techniques for reducing big if statements and nested for loops and other st...

Can we create static array with a size that is an execute-time constant?

We all know the basic rules for static array: int size = 20; char myArray[size]; is not legal. And. const int size = 20; char myArray[size]; is OK. But, what about this. int f(const int size) { char myArr[size]; } void main() { f(2); f(1024); } MSVC says it is an error, gcc seems to compile and execute it fine. Obvi...

python style: inline function that needs no inlining?

I'mm writing gtk code. I often have short callbacks that don't need to be closures, as they are passed all the parameters they need. For example, I have this in a loop when creating some gtk.TreeViewColumns: def widthChanged(MAINCOL, SPEC, SUBCOL, expandable): if expandable: return w = MAINCOL.get_width() SUBCOL.set_fixed_wi...

Is it considered a good style to use whitespace to align the code?

For example, what piece of code is considered better styled? If I show my code to a professional developer and ask if my code is good or not, will using the second style be probably considered as a (minor, but...) minus or a plus to my code quality? I myself tend to like the second style but would prefer to comply to the most common opi...

Advantages of using arrays instead of std::vector?

I'm currently seeing a lot of questions which are tagged C++ and are about handling arrays. There even are questions which ask about methods/features for arrays which a std::vector would provide without any magic. So I'm wondering why so much developers are chosing arrays over std::vector in C++? ...

TextMate Code Formatter for C

I am working on a C assignment for uni, and I've been coding in TextMate and compiling in the command line. But TextMate wont (or cant) format C code, as it would for say, HTML, Ruby or PHP (using SHIFT + CTRL + F). Is there a plugin or some other tool I can use to fix my indenting and curly braces for .c files? ...

Is it bad that I don't follow PEP 8 and cut my lines at 79 characters?

I think every Python code has seen PEP 8. The part that sticks out to me is: Limit all lines to a maximum of 79 characters. I'm sitting here on a widescreen monitor and coding right across the screen. I'm not coding in a terminal and don't plan on coding in a terminal. I therefor have no problems with character-line limits. How many ...

Tips for a light PHP Framework

Hi everyone! I'm trying to write down some concrete ideas for a light framework (on PHP5), with the purpose to handle a lot of requests and to make it scale well in terms of high traffic eventualities. I've already started it, but I'm not really satisfied about the coding style, which is basically composed by simple classes and helpers,...

Using { } to segment large blocks of code to improve code-readability - Good practice?

Hello, I'm considering the option of using anonymous { } code blocks to logically distinguish "code blocks" inside the same method call, something that (theoretically) should improve readability of the code. I'm wondering which of the following 2 code segments is better to your eyes? Also, are the 2 code segments compile to the same b...

Python: Is it bad style to give an argument the same name as the function?

Consider the following code: def localize(value, localize=None): # do something with the localize argument The localize variable contains information whether the global localization setting should be respected or not. It is called by the same name through three layers of code. What's the lesser evil, shadow the function name wi...

C - Checking for NULL values

I am coming across situations such as this: if(x == NULL) { printf(" The value of X is Null, exiting.."); return -1; } and this "situation" gets repeated many , many times..... laziness aside is there a better way to write this ? Cheers! ...

Why do most C developers use define instead of const?

In many programs a #define serves the same purpose as a constant. For example. #define FIELD_WIDTH 10 const int fieldWidth = 10; I commonly see the first form preferred over the other, relying on the pre-processor to handle what is basically an application decision. Is there a reason for this tradition? ...

Why does .NET's StringValidator's Validate method throws an exception when it doesn't succeed?

As you can see in the MSDN StringValidator documentation, the Validate method returns void. If validation doesn't succeed the Validate method throws ArgumentException. I thought that "You only throw an exception when something exceptional happens". Surely a validator that failed to validate isn't exceptional.. Why not return bool? What a...

coding style: use parameter or instance variable?

I often have functions which take a parameter, set an instance variable to that parameter, and then do other things, e.g.: def updateFoo(self, foo): self.foo = foo fooProcessor1(foo) fooProcessor2(self.foo) Do you prefer to pass the parameter itself, as in fooProcessor1, or the newly-set instance variable, as in fooProcess...

C# - Bad Practices

What are some of the bad practices you have seen in C# or .NET in general, there are plenty of posts on "good" practices, but I have not seen one on bad practices. If this is OT then please delete. ...

Using non-persistence related methods and fields in persistence entity

I have a persistence related java-ee code which I need to rewrite to make the app work on the Google App Engine and its data storage. When I use java-ee persistence providers, I generate persistence entities with my IDE and I keep them the way they are in case I need to regenerate them. However autogenerating entity classes for app-engin...