coding-style

Naming member functions/methods with a single underscore, good style or bad?

In some languages where you cannot override the () operator, I have seen methods with a single underscore, usually for 'helper' classes. Something likes this: class D10 { public function _() { return rand(1,10); } } Is it better to have the function called Roll()? Is a underscore fine? After all, there is only one func...

Unnecessary 'else' statement

As you know, in Eclipse you can turn on "Unnecessary 'else' statement" check that will trigger on if-then-else with premature return. And, from my experience, there are two most possible situations when use such statement: 1) Pre-check: if (!validate(arg1)) { return false; } doLotOfStuff(); 2) Post-check: doLotOfStuff(); if (con...

Multiple if blocks or a single if with AND condition

If I need to check multiple conditions, which is the preferred way with respect to performance if( CND1 && CND2 && CND3 && CND4) { } else { } or if(CND1) { if(CND2) { if(CND3) { if(CND4) { } else { } } else { } } else { } } ...

phpbb specific forum page styles

I am using phpbb on a site for a client, and the client has requested that each different forum page have a different background color. Such functionality is not built into phpbb (from what I can tell), so how should I go about doing this? Can I modify the code of phpbb directly? My other thought was to use a js conditional statement, ...

First Time Working With Others?

I've been at my very first programming job for about 8 months now and I've learned incredible amounts so far. Unfortunately, I'm the sole developer for a small startup company for internal applications. For the first time ever though, I'll be handing off some of my projects to someone else when I leave this job. I've documented all my...

Good programming style when handling multiple objects

I've been programming a software version of a board game. Thus far I have written the classes which will correspond to physical objects on the game board. I'm well into writing the program logic, however I've found that many of the logic classes require access to the same objects. At first I was passing the appropriate objects to method...

special debugging lines (java)

Recently i've found myself writing a lot of methods with what i can only think to call debugging scaffolding. Here's an example: public static void printArray (String[] array, boolean bug) { for (int i = 0; i<array.lenght; i++) { if (bug) System.out.print (i) ; //this line is what i'm calling the debugging scaffoldi...

typeof === "undefined" vs. != null

I often see JavaScript code which checks for undefined parameters etc. this way: if (typeof input !== "undefined") { // do stuff } This seems kind of wasteful, since it involves both a type lookup and a string comparison, not to mention its verbosity. It's needed because 'undefined' could be renamed, though. My question is: How is...

Do you know any style guide for Python?

Do you know any style guide for Python like "Code Like a Pythonista"? I found chapter 2.3.4 of Expert Python Programming very interesting too. ...

How to name variables which are structs

Hello, i often work on private projects using the WinApi, and as you might know, it has thousands of named and typedefed structs like MEMORY_BASIC_INFORMATION. I will stick to this one in my question, what still is preferred, or better when you want to name a variable of this type. Is there some kind of style guide for this case? For ...

PHP beautifiers (libraries for formatting code)

Previously, my intention was to ask: Do you know any open source SQL formatter/beautifier library for PHP projects? But I think, I'd better ask: Which code formatting libraries written in PHP are the best? Let's list them all in one place. My types: for CSS syntax: Css Tidy for PHP: PEAR's PHP_Beautifier for HTML syntax: Tidy E...

Python `if x is not None` or `if not x is None`?

I've always thought of the if not x is None version to be more clear, but Google's style guide implies (based on this excerpt) that they use if x is not None. Is there any minor performance difference (I'm assuming not), and is there any case where one really doesn't fit (making the other a clear winner for my convention)?* *I'm referri...

Do you put a super() call a the beginning of your constructors?

This is a question about coding style and recommended practices: As explained in the answers to the question unnecessary to put super() in constructor?, if you write a constructor for a class that is supposed to use the default (no-arg) constructor from the superclass, you may call super() at the beginning of your constructor: public M...

"Verbose Dictionary" in C#, 'override new' this[] or implement IDictionary

All I want is a dictionary which tells me which key it couldn't find, rather than just saying The given key was not present in the dictionary. I briefly considered doing a subclass with override new this[TKey key], but felt it was a bit hacky, so I've gone with implementing the IDictionary interface, and passing everything through direc...

how to write clean code in c# language and improve quality of code.

how i can improve our code quality and write clean code. if i write a unclean ugly code then how i can migrate as a good code (beautiful and clean). ...

Should I use `import os.path` or `import os`?

According to the official documentation, os.path is a module. Thus, what is the preferred way of importing it? # Should I always import it explicitly? import os.path Or... # Is importing os enough? import os Please DON'T answer "importing os works for me". I know, it works for me too right now (as of Python 2.6). What I want to kno...

Python indentation in "empty lines"

Which is preferred ("." indicating whitespace)? A) def foo(): x = 1 y = 2 .... if True: bar() B) def foo(): x = 1 y = 2 if True: bar() My intuition would be B (that's also what vim does for me), but I see people using A) all the time. Is it just because most of the editors out there are bro...

Java coding style

How do you keep yourself coding to standards? There is stylecop and resharper for C#. Are there any tools/eclipse plugins for code analisys in Java? Which of them do you use? ...

While programming, what to do when facing with a seemingly unsolvable situation with a time limit?

This is not a technical question, but rather a social and methodical one. I am a computer sciences student and I usually have really tough programming assignments. I don`t know if it is only happening to me but sometimes, particularly when deadline is approaching, i find myself in a harsh situation. I cannot find my mistake in the code o...

What is a good rule for when to prepend members with 'this' (C#)?

If I am accessing a member field, property, or method, I'm never sure when I should prepend it with 'this'. I am not asking about cases where it is required, like in the case where a local variable has the same name. I am talking about cases where the meaning is exactly the same. Which is more readable? Are there any standards, best ...