coding-style

Enforcing using the class name whenever a shared member is accessed.

We have a coding standard that says all shared (static) fields and methods must be called with the class name. E.g. NameOfClass.whatever Rather then whatever Is there a tool that we can use to check this is in fact the case? (Likewise for modules) Sorry I should have make it clearer we are using VB.NET. This is a bigger exam...

How to neatly avoid C casts losing truth

I'm quite happy that, in C, things like this are bad code: (var_a == var_b) ? TRUE : FALSE However, what's the best way of dealing with this: /* Header stuff */ #define INTERESTING_FLAG 0x80000000 typedef short int BOOL; void func(BOOL); /* Code */ int main(int argc, char *argv[]) { unsigned long int flags = 0x00000000; ...

Ordering columns in DB tables

When it comes to column order in DB tables, are there any standards or at least best practices? Here are a few handmade best practices that I've adopted: primary key comes first; foreign keys come after the primary key; columns holding user generated data come after the foreign keys; timestamp columns come in the end of the table (no ...

which style is preferred?

Option 1: def f1(c): d = { "USA": "N.Y.", "China": "Shanghai" } if c in d: return d[c] return "N/A" Option 2: def f2(c): d = { "USA": "N.Y.", "China": "Shanghai" } try: return d[c] except: return "N/A" So that I can then call: for c in ("China", "Japan"): for f in (f1, f2): prin...

Accessing members in your own class: use (auto)properties or not?

I've created this "question" as a community-wiki, because there is no right or wrong answer. I only would like to know how the community feels about this specific issue. When you have a class with instance variables, and you also created properties that are simply getters and setters for these instance variables, should you use the prop...

Quick Advice: How should this be written in Ruby?

I am a Java/C++ programmer and Ruby is my first scripting language. I sometimes find that I am not using it as productively as I could in some areas, like this one for example: Objective: to parse only certain lines from a file. The pattern I am going with is that there is one very large line with a size greater than 15, the rest are de...

Functions should start with "Get"?

Hi, I'm trying to look at the C# Coding Standards to make my code more beautiful and standard, and I have a question: Does functions (methods that are not voids), according to the C# coding standards, should start with "Get"? For example: "GetSongOrder()", "GetNextLine()" etc? Thanks. ...

Using do block vs brackets {}

New to ruby, put on your newbie gloves. Is there any difference (obscure or practical) between the following two snippets? my_array = [:uno, :dos, :tres] my_array.each { |item| puts item } my_array = [:uno, :dos, :tres] my_array.each do |item| puts item end I realize the bracket syntax would allow you to place the block on...

What StyleCop like tools are there for VB.NET

see also VB.NET Static Code Anaylsis For better or for worst we now have a VB.NET coding standards document that is based on a C# coding standard as enforced by StyleCop. For example the number of spaces you should put in each side of a “+” sign etc all instance Members (fields and methods!) must be access as “me.fieldName” all sha...

Should I redundantly test arguments (e.g collection emptiness)?

Is there a problem with the redundant collection checking here?: SomeMethod() { shapes = GetShapes(); //maybe Assert(shapes.Any())? if(shapes.Any()) { ToggleVisibility(shapes); } } ToggleVisibility(IEnumerable<Shape> shapes) { //maybe Assert(shapes.Any())? if(shapes.Any()) { //do stuff ...

Android private fields naming guidelines are ok?

Here http://source.android.com/submit-patches/code-style-guide#shortmethods it is stated that : "Field Names * Non-public, non-static field names start with m. * Static field names start with s. * Other fields start with a lower case letter. * Public static final fields (constants) are ALL_CAPS_WITH_UNDERSCORES. " also s...

What is your preferred coding style for dealloc in Objective-C?

I know that discussions about coding styles tend to end in disaster and endless flame wars, but that’s not what I want to reach. During the last decade I mainly saw two different coding styles for dealloc methods in Objective-C. The first and most common one was to place dealloc at the bottom of the file. This is also the style Apple use...

Use of conditional operator to select which object calls a particular method?

I have two collections, and items that are added to one or the other of those collections based on whether some criteria is met. Somewhat inadvertantly, I stumbled on the fact that it is legal to write (test(foo) ? cOne : cTheOther).add(foo); instead of if (test(foo)) { cOne.add(foo); } else { cTheOther.add(foo); } While the fir...

Does a persons' first programming language affect their programming style and if so, how?

I was speaking to an experienced lecturer recently who told me he could usually tell which programming language a student had learnt to program in by looking at their coding style (more specifically, when programming in other languages to the one which they were most comfortable with). He said that there have been multiple times when he'...

Codeigniter application design

Hello, I have several questions regarding CI application design. Q. When creating a new form and your using CI's form_helper I'm creating arrays in the controller and passing it to the view/form_input() method. Should I be doing this in the controller, the view, or a separate file? Q. In my controller, I create a method for my form...

Rowspan when <a> element is clicked with Jquery?

Hi all, I was trying to get this with divs and css, but I was advice to do it with JQuery and tables instead. The case is that I am trying to make a two rows table with 5 cells in first row and 4 on second. When you click on one of the inside of the cells on the top, that cell will span the row and change background-image, taking th...

C++: Template Parameter Cyclic Dependency

Hello, This is more a best practice question than a language question in itself, since I already have a working solution to what seems to be a common stumbling block in C++. I'm dealing with a typical cyclic dependency issue in template parameter substitutions. I have the following pair of classes: template<class X> class A { /* ... *...

How do you work with a programmer with a radically different coding style?

Has anyone worked with a programmer with a radically different coding style? How do you jive together without wanting to delete and rewrite each others code? ...

C# style prefered spacing between regions, between methods, and between properites

what is considered best practice from a code readability standpoint regarding spacing? Are there any really good C# style guides out there? ...

C# coding style - line length / wrapping lines

Does line wrapping help with code readability? Is there a generally accepted etiquette for using line continuations? Why use this: SomeMethod(int someInt, Object someObject, String someString, bool someBool) { ... } Instead of this: SomeMethod(int someInt, Object someObject, String someString, bool someBool) { ... } Ed...