coding-style

What should I do to improve my code/style of programming?

I am sure you guys know me. I am the person from your offshore team whose code puts you off and at times makes you pull your hair (bcoz you can't pull mine). My programming concepts are quite okay (and I continuously try and improve them by reading blogs, articles). But, my code isn't up to the mark. It has got better with experience, bu...

To iterate or to use a counter, that is the question

Whenever someone starts using the STL and they have a vector, you usually see: vector<int> vec ; //... code ... for( vector<int>::iterator iter = vec.begin() ; iter != vec.end() ; ++iter ) { // do stuff } I just find that whole vector<int>::iterator syntax sickitating. I know you can typedef vector<int>::iterator VecI...

How should I organise my functions with pyparsing?

I am parsing a file with python and pyparsing (it's the report file for PSAT in Matlab but that isn't important). here is what I have so far. I think it's a mess and would like some advice on how to improve it. Specifically, how should I organise my grammar definitions with pyparsing? Should I have all my grammar definitions in one fun...

C++ good coding style - always fully qualify library types?

What is generally considered good coding style in C++ where you use types from the standard library? For example, if I have a using namespace std; directive would you still expect to see library types fully qualified like so: std::string or is it acceptable to just use string as the type identifier? If you do fully qualify, can you expa...

PHP codesniffer - how to teach it to ignore white space?

I am using PHP CodeSniffer to check if my code complies to Zend standards. 80 chars per line is one of them. But I prefer to indent line with white spaces and sniffer treat short lines with line indentations as long lines. Is there a way to teach it to ignore whitespace identations? Or it makes sense and the farther my line is indented,...

include boost header file using "" or <>

Why tuple documentation for example says to use: #include "boost/tuple/tuple.hpp" and not #include <boost/tuple/tuple.hpp> I know that it's almost not probably my code will have also boost/tuple/tuple.hpp, but using include <> states explicitly not to look in the curent directory. So what is the reason? ...

Plural/singular naming in methods returning lists.

it seems a trivial point, until you realize that you need consistency. Not being a native English speaker, I prefer to ask both for grammar and for style. Which one must be preferred among these method names, returning a list of URIs, each one associated to an object? objectUriList() objectsUriList() objectUrisList() objectsUrisList() ...

Are DefType statments considered Bad Practice?

I want your thoughts on why or (why not) this statement should (or should not) be used. Since this is a little subjective, here is my criteria: Upvotes given for concrete reasons (as opposed to unreasoned opinion). Final answer accepted will be the most comprehensive answer. ...

Would VS2008 c++ compiler optimize the following if statement?

if (false == x) { ...} as opposed to: if (!x) { ... } and if (false == f1()) { ...} as opposed to: if (!f1()) { ... } I think the if(false == ... version is more readable. Do you agree, or have another trick you can propose? Will it be just as fast? Thanks. This is why I do not like !x: if (25 == a->function1(12345, 6789) &&...

If we use the C prefix for classes, should we use it for struct also?

Assuming that a project has been using the C class prefix for a long time, and it would be a waste of time to change at a late stage, and that the person who originally wrote the style guide has been hit by a bus, and that there are no structs in the code already... It's a pretty trivial question, but if a C++ code style guide says "use...

Python import mechanics

I have two related Python 'import' questions. They are easily testable, but I want answers that are language-defined and not implementation-specific, and I'm also interested in style/convention, so I'm asking here instead. 1) If module A imports module B, and module B imports module C, can code in module A reference module C without an...

Dealing with ugly SQL in Java

Here goes a SQL-Java coding style question... How do others here deal with creating complex custom queries in Java cleanly? I am speaking of the seemingly simple task of preparing a string which is the SQL statement to be executed. I am aware of HQL, and also of stored procedures, but honestly I don't really love these solutions. Perh...

Get all elements in array besides the first one.. ? (php)

Is there a way to specify getting all but the first element in an array? I generally use foreach() to loop through my arrays. say array(1,2,3,4,5), i would only want 2, 3, 4 ,5 to show and for it to skip 1. ...

Visual Assist X: curly braces are moving during refactoring

I use Visual Assist X, build from 05.01.2009, but the same problem occurred in the previous releases as well. (I run it on MSVS 2005) When I do some refactoring (like extracting a method), everything's fine, but all the curly braces move forward. For example, before refactoring the code looked like this: while (expr) { doSmth(); } ...

What name should I give my function? And who can I ask next time?

Background: There are a few threads on SO about how to choose names for variables and functions. It dawned up on me that there might be a use for a site where you could go and ask random people what name a particular function should have. You describe the behavior, and they come up with a name. The benefit of this, you get multiple pers...

Passing hashes instead of method parameters

I see that in Ruby (and dynamically typed languages, in general) a very common practice is to pass a hash, instead of declaring concrete method parameters. For example, instead of declaring a method with parameters and calling it like this: def my_method(width, height, show_border) my_method(400, 50, false) you can do it this way: de...

Does resharper make you lazy?

I've been looking at using resharper and from the reviews I've seen, people who start using it never go back. I'm wondering if using resharper helps you pick up errors when looking at code without resharper, or does it decrease this ability becaues you get use to relying on resharper to identify problems? ...

CSS margins: aligning a list against a float-left image

Hi, The following is my first cut at coding-up a reddit-like comment in html+css. I have a few questions about css and the general structure: How do I get the comment body ("The King took off his hat...") to align with the comment head ("Nathan, posted...") and the comment tail ("reply permalink ...")? I tried making the margin-bottom ...

ASP.NET - Placement of @ Register directive

In the past I have always placed my <%@ Register ... %> directive(s) at the top of my .aspx pages just below the @ Page directive. I recently found out that I can place this register directive ANYWHERE in the .aspx page and still have it function correctly. We are wondering if there is any problem people can foresee with placing these ...

What is your preferred style for naming variables in R?

Which conventions for naming variables and functions do you favor in R code? As far as I can tell, there are several different conventions, all of which coexist in cacophonous harmony: 1. Use of period separator, e.g. stock.prices <- c(12.01, 10.12) col.names <- c('symbol','price') Pros: Has historical precedence in the R...