coding-style

Expert in one language or know more languages

In the corporate world, Is it better to be knowledgeable(by knowledgeable I mean not a expert or novice but with some coding experience) about multiple languages. or is it better to be an expert in one language(say c++ or java) but having just basic knowledge on others. I ask this question because what I feel is languages can be dif...

Any problem with doing the main work of a class in its constructor?

I have always felt that in general the main work of a class should be done in its instance methods, while the constructor should only get the instance into a usable inital state. But I find that in practice there are situations where it seems to make more sense to put essentially all the actual work into the constructor. One example: I...

In PHP is it better to code first even if it is messy and then apply coding style?

Once the code works, we have all the time in the world to make it look good. If we need to make sudden rapid changes, then we have no choice other than messing up standard coding style. Is this way professional and widely used? Or is it better to form the habit of maintaining perfect order while coding at every point in time? ...

why C# and C++ use _<variableName> coding convention?

Hi... I have seen too much C# and C++ code where the variable naming convention seems to ask programmers to write variable names using underscore before the text of the variable. e.gr. int? _countMoney; What's the rationale supporting that convention? ...

What's the Rails way to mirror an LDAP directory as a SQL table?

So I'm creating a Rails app that will function as a directory for contact information in our organization. But it's not as simple as it sounds. We have a large LDAP-enabled directory which contains information for all of the users in our organization of tens of thousands. We have a smaller, separate LDAP-enabled directory which contain...

Elegant way to handle "impossible" code paths

Occasionally I'll have a situation where I've written some code and, based on its logic, a certain path is impossible. For example: activeGames = [10, 20, 30] limit = 4 def getBestActiveGameStat(): if not activeGames: return None return max(activeGames) def bah(): if limit == 0: return "Limit is 0" if len(activeGames)...

Is it always a bad idea to use + to concatenate strings

I have code as follows : String s = ""; for (My my : myList) { s += my.getX(); } Findbugs always reports error when I do this. ...

Can someone cite a good reference for programming with exceptions?

I prefer to have the "rc" error-code return style of error management. I agree that this presents challenges that are better served by throw-catch, however, I still feel that I am not designing and implementing in a style that is clean and maintainable. So, I am looking for a good book that discusses the pattern and is not simply a ref...

Method naming convention

If a method takes a class/struct as an input parameter, what is the best way to name it? Example: class Person{} class Address{} class Utility{ //name **style 1** - use method overloading public void Save(Person p){} public void Save(Address a){} *//name **style 2** - use unique names that define what they are doing //or p...

php OOP Exceptions or die()?

I am developing some project. And I want to control different errors. I know that in all popular frameworks and php projects there are different Exceptions. But I think that is not required work. If the error is occured we can make die() with our message. 1. What are the main pluses of Exceptions? 2. Can I control my errors with die()? ...

Using comma to prevent the need for brace pair

Sometimes, when I have a multi-case if, or a very simple for, with only two statements, I will forgo braces, instead using the comma. Is this a bad exploitation of the feature, and is it ugly and bad form? Or is it an acceptable way to save time and space? For example: if (something) b = y, c = z--; instead of: if (something) { ...

How to simulate multiple inheritance without interfaces?

How can I simulate multiple inheritance in C# without using interfaces. I do believe, interfaces abilityes are not intended for this task. I'm looking for more 'design pattern' oriented way. ...

If error then switch vs. switch with "good" case

Hello all. I'm not very familiar with machine code, but I think this is a pretty simple question. If I want to do error handling via an integer returned from a function (as opposed to the function throwing an exception), is it better practice—from a machine code standpoint—to: Check the integer in a conditional statement for a "bad"...

What is rc stands for

Hi, I saw a lot of times code where return status of function was set to *rc * variable (e.g. int rc = foo();). I though it some sort of convention and blindly used it all over my code. Recently was asked by colleague what *rc * stands for and discovered that I indeed don't know the answer. Thanks ...

style opinion re. empty If block

I'm trying to curb some of the bad habits of a self-proclaimed "senior programmer." He insists on writing If blocks like this: if (expression) {} else { statements } Or as he usually writes it in classic ASP VBScript: If expression Then Else statements End If The expression could be something as easily negated as: if (x =...

Why use a for loop instead of a while loop?

Possible Duplicates: Iterate with for loop or while loop? Loops in C - for() or while() - which is BEST? When should one use a for loop instead of a while loop? I think the following loops are identical, except for their syntax. If so, then why choose one over the other? int i; for (i = 0; i < arr.length; i++) { // do w...

Is it good or bad manner to oversecure?

If a function does all proper checks inside, should I check everything before calling it, or better not? Is security redundancy considered a good practice? Example (in a sort of C#-like pseudocode with by-reference arguments passing): doSomething(vector v) { ...; v.clear; useCleanVector(v) } useCleanVector(vector v) { if(!v....

What are your Personal Templates?

After having written thousands and thousands of lines of code in a given language, you end up having your own personal templates. This is, code structures that you repeatedly use to address the same problems, or express the same ideas. Most of these "personal templates" are polished versions of simple solutions, cleaner or easier ways t...

Anyone have a favorite Python coding style enforcer?

I'm trying to find a Python coding style enforcer (tool, not person!). Any recommendations? --Steve ...

Do Java exceptions deserve their own file?

Whenever I define a new exception, I tend to do one of two things: Create an exceptions file which contains a listing of all the new exceptions defined in my project. Put each defined exception in the same file as the class in which it is thrown. Netbeans doesn't doesn't like it when I have a public exception defined in the same file...