coding-style

best practice when referring to a program's name in C

what is considered best practice when referring to a program's name? i've seen #define PROGRAM_NAME "myprog" printf("this is %s\n", PROGRAM_NAME); as well as printf("this is %s\n", argv[0]); i know, that the second approach will give me ./myprog rather than myprog when the program is not called from $PATH and that the first approac...

Best style for Python programs: what do you suggest?

A friend of mine wanted help learning to program, so he gave me all the programs that he wrote for his previous classes. The last program that he wrote was an encryption program, and after rewriting all his programs in Python, this is how his encryption program turned out (after adding my own requirements). #! /usr/bin/env python #####...

best practice on precedence of variable declaration and error handling in C

is there an advantage in one of the following two approaches over the other? here it is first tested, whether fopen succeeds at all and then all the variable declarations take place, to ensure they are not carried out, since they mustn't have had to void func(void) { FILE *fd; if ((fd = fopen("blafoo", "+r")) == NULL ) { ...

What is the best way to use whitespace while programming?

I'm fairly new to programming and from learning I have seen different ways of formatting code, comments, etc; and have been recommended on different techniques. I mostly program in C#, C++, and Java so I want to know what is the the best way to layout code so that if other people where to go through it, they would be impressed by how si...

Which style of return is "better" for a method that might return None?

I have a method that will either return an object or None if the lookup fails. Which style of the following is better? def get_foo(needle): haystack = object_dict() if needle not in haystack: return None return haystack[needle] or, def get_foo(needle): haystack = object_dict() try: return haystack[needle] ...

What is a more "ruby way" to write this code?

This was a homework assignment for my students (I am a teaching assistant) in c and I am trying to learn Ruby, so I thought I would code it up. The goal is to read integers from a redirected file and print some simple information. The first line in the file is the number of elements, and then each integer resides on its own line. This...

Number of characters recommended for a statement

Hi, I have been using Qt 4.5 and so do C++. I have been told that it's a standard practice to maintain the length of each statement in the application to 80 characters. Even in Qt creator we can make a right border visible so that we can know whether we are crossing the 80 characters limit. But my question is, Is it really a standard ...

In Objective C, is there a difference between if (object == nil) and if (nil == object)?

I would lean towards if (object == nil) but I've noticed in some tutorials the use of if (nil == object) Is this just a style thing, or is there some justified rationale for using either format? ...

How to organize delegate files

In cocoa-touch development... Use AppDelegate for delegate classes Create separate delegate class and locate in new .h/.m for each class need to use delegate Use view controller classes(whenever such exist) to do that job for all classes managed by this controller What would you recommend? ...

Is GOTO really as evil as we are led to believe?

Possible Duplicates: GOTO still considered harmful? GoTo statements and alternatives in VB.NET I'm a young programmer, so all my working life I've been told GOTO is evil, don't use it, if you do, your first born son will die. Recently, I've realized that GOTO actually still exists in .NET and I was wondering, is GOTO really...

What is the C# static fields naming convention?

I have recently started using ReSharper which is a fantastic tool. Today I came across a naming rule for static fields, namely prefixing with an underscore ie. private static string _myString; Is this really the standard way to name static variables? If so is it just personal preference and style, or does it have some sort of lower ...

Is there a perl module that can start a process and return the three main I/O handles to that process?

In perl, I often need to run a child process, send some input to it, and then read its output. There are a number of modules to do this, but they all seem to require you to pass in pre-existing variables, which are then modified by the function to contain filehandles. Here is an example from the Synopsis of IPC::Open3: my ($wtr, $rdr, $...

Smart approach to CSS3

Hi, do You have any elegant approach to benefit from CSS3 features, like border radius or gradients? I am looking for a solution that would avoid browser-specific CSS properties and browser-specific stylesheet files. I find them both hard to maintain and too verbose. It could be a Javascript library that would take care of cross-brows...

Is using something like the MvcContrib Grid a step backwards in code readability?

I mean, now we have all this movement towards separating your html markup from your code as much as possible using modern template engines (in the old days programmers usually just kept concatenating strings in php, which was terrible.) Then I look at a co-worker's code for generating an html table, and it looks like: <% Html.Grid(Mode...

Do teams need a code supervisor?

I think we quite agree programming must be more boring than programmers are able to manage (specially when you leave them alone). Even more if there are coding guidelines. What do you think about having a supervisor profile in a small team? Have you managed to avoid this figure? Maybe it is not possible so the effort is for nothing. ...

ObjectPascal identifier naming style on other languages

I learned to program with delphi, and i always liked the object pascal code style, looks very intuitive and clean. When you look at the variable declaration, you know what are you dealing with.. A fast summary: Exception E EMyError Classes and Types T TMyClass Fields in classes f fVisible Events On OnMouseDown Pointer types...

Idiomatic Erlang help

I've got an Erlang snippet here that I'd like to work into more idiomatic Erlang, rather than a crude Python translation. Process takes a pairs of congruent lists and combines them. Some of the elements need to be taken from one lists or the other, based on their properties, while the rest of the elements need to be summed. It works pro...

codestyle; put javadoc before or after annotation?

I know that it isn't the most vital of issues, but I just realised that I can put the javadoc comment block before or after the annotation. What would we want to adopt as a coding standard? /** * This is a javadoc comment before the annotation */ @Component public class MyClass { @Autowired /** * This is a javadoc comme...

Programmers dictionary/lexicon for non native speakers

I'm not an English speaker, and I'm not very good at English. I'm self thought. I have not worked together with others on a common codebase. I don't have any friends who program. I don't work with other programmers (at least nobody who cares about these things). I guess this might explain some of my problems in finding good unambiguous ...

Do you know any style guide for VB6?

I code with Vb6 everyday using my own convention and i'm starting to feel guilty about that. Do you know any style guides for VB6 like naming convention, code techniques and best practices? ...