Coding style is a set of guidelines that helps readability and understanding of the source code.

learn more… | top users | synonyms (1)

22
votes
8answers
2k views

Should comments say WHY the program is doing what it is doing? (opinion on a dictum by the inventor of Forth) [duplicate]

The often provocative Chuck Moore (inventor of the Forth language) gave the following advice[1]: Use comments sparingly! (I bet that's welcome.) Remember that program you looked through - the ...
10
votes
1answer
783 views

Are there well-known PowerShell coding conventions?

Are there any well-defined conventions when programming in PowerShell? For example, in scripts which are to be maintained long-term, do we need to: Use the real cmdlet name or alias? Specify the ...
2
votes
3answers
275 views

using “IS” is better or checking for “NOT NULL”

In C#.NET language: This style of coding is recommended or the one below it? if (sheet.Models.Data is GroupDataModel) { GroupDataModel gdm = ...
9
votes
2answers
322 views

Use an else after exception (or not)

Consider this bit of code: if (x == 1) { throw "no good; aborting" ; } [... more code ...] Now consider this code: if (x == 1) { throw "no good; aborting" ; } else { [... more code ...] } ...
8
votes
2answers
182 views

Where should I define constants in scripts?

When writing scripts using a modern scripting language, e.g. Powershell or JavaScript, where should I define constants? Should I make all constants global for readability and ease of use, or does it ...
1
vote
4answers
495 views

Long lines of text in source code [duplicate]

Possible Duplicate: Is the 80 character limit still relevant in times of widescreen monitors? I used to set a vertical line set at 80 characters in my text editor and then I added carriage ...
6
votes
4answers
2k views

Switch or a Dictionary when assigning to new object

Recently, I've come to prefer mapping 1-1 relationships using Dictionaries instead of Switch statements. I find it to be a little faster to write and easier to mentally process. Unfortunately, when ...
12
votes
2answers
317 views

is there any elegant way to analyze an engineer's process?

Plenty of sentiment exists that measuring commits is inappropriate. Has any study been done that tries to draw in more sources than commits - such as: browsing patterns IDE work (pre-commit) idle ...
1
vote
4answers
420 views

Is extensive documentation a code smell? [closed]

Every library, open-source project, and SDK/API I've ever come across has come packaged with a (usually large) documentation file, and this seems contradictory to the wide-spread belief that good code ...
4
votes
2answers
322 views

What should my “large codebase sample” look like?

If an employer asks for a large code sample, one for an entire project, what characteristics should the project have to show architectural skills and the ability to manage a large codebase? For ...
8
votes
7answers
1k views

Why would an employer ask for a 'long' code sample?

What would a large project that spanned multiple files and >1000 lines show to an employer that a few individual files and a couple hundred lines couldn't capture?
8
votes
7answers
314 views

How does a variable introduce state?

I was reading the "C++ Coding Standards" and this line was there: Variables introduce state, and you should have to deal with as little state as possible, with lifetimes as short as possible. ...
6
votes
3answers
262 views

Style bits vs. Separate bool's

My main platform (WinAPI) still heavily uses bits for control styles etc. (example). When introducing custom controls, I'm permanently wondering whether to follow that style or rather use individual ...
10
votes
5answers
561 views

Should coding standards be enforced by the continuous integration server?

Should coding standards/style be enforced by the continuous integration server running static analysis tools (ex. PMD, StyleCop/FxCop) and failing the build if the standards are not followed? What ...
6
votes
3answers
245 views

How should I get my code ready for OpenSourcing it and putting it on GitHub?

In a few weeks, my project is going to be finished and I want to start getting my code ready for other people to use it. I am going to be posting everything to GitHub so people can tweak it and ...
2
votes
1answer
213 views

How do I organize a GUI application for passing around events and for setting up reads from a shared resource

My tools involved here are GTK and Haskell. My questions are probably pretty trivial for anyone who has done significant GUI work, but I've been off in the equivalent of CGI applications for my whole ...
26
votes
9answers
2k views

Simple vs Complex (but performance efficient) solution - which one to choose and when?

I have been programming for a couple of years and have often found myself at a dilemma. There are two solutions - one is simple one i.e. simple approach, easier to understand and maintain. It ...
3
votes
3answers
153 views

conventions for friend methods in Perl

Perl doesn't support a friend relationship between objects, nor does it support private or protected methods. What is usually done for private methods is to prefix the name with an underscore. I ...
3
votes
6answers
2k views

Using prefix incremented loops in C#

Back when I started programming in college, a friend encouraged me to use the prefix incrementation operator ++i instead of the postfix i++, citing that there was a slight chance of better performance ...
5
votes
4answers
633 views

Method flags as arguments or as member variables?

I think the title "Method flags as arguments or as member variables?" may be suboptimal, but as I'm missing any better terminology atm., here goes: I'm currently trying to get my head around the ...
9
votes
4answers
452 views

How to avoid general names for abstract classes?

In general it's good to avoid words like "handle" or "process" as part of routine names and class names, unless you are dealing with (e.g.) file handles or (e.g.) unix processes. However abstract ...
-5
votes
2answers
444 views

Is there any reason why I should use parentheses when calling new in PHP?

When there are no arguments, we have these two options: $obj = new MyClass; vs. $obj = new MyClass(); I always pick the former, just because. Any thoughts?
11
votes
9answers
944 views

Should a programmer take writing lessons to enhance code expressiveness?

Given that programmers are authors and write code to express abstract thoughts and concepts, and good code should be read by other programmers without difficulties and misunderstandings, should a ...
15
votes
12answers
2k views

Teaching myself, as a physicist, to become a better programmer

I've always liked physics, and I've always liked coding, so when I got the offer for a PhD position doing numerical physics (details are not relevant, it's mostly parallel programming for a cluster) ...
69
votes
15answers
3k views

Is defining a variable to name a method argument a good practice?

For the sake of readability I often find myself defining temporary variables while calling functions, such as the following code var preventUndo = true; doSomething(preventUndo); The shorter ...
17
votes
5answers
2k views

What are the benefits of prefixing function parameter names with p*?

I often see projects (in Java projects and teams using Eclipse) that prefix function parameters with p. For example public void filter (Result pResult) ... I personally don't see any benefit in ...
6
votes
3answers
2k views

Should I prefer properties with or without private fields?

The codebase I'm working in now has the convention of using private fields and public properties. For example, most classes have their members defined like this: // Fields private double _foo; ...
7
votes
3answers
585 views

What statements and approaches should I avoid when learning functional programming?

I have 6 years of programming experience, mostly following the object oriented paradigm, and I'm interested in learning functional programming. My main goal is to become a functional paradigm ...
4
votes
4answers
1k views

Should I put newlines before or after binary operators? [closed]

When you're in Python or Javascript, you should always put binary operators at the end of the previous line, in order to prevent newlines from terminating your code prematurely; it helps you catch ...
1
vote
7answers
12k views

If condition not true: default value or else clause? [closed]

I have searched Programmers and Stackoverflow and was not able to come up with a satisfying answer, even though I'm quite sure it must have been asked many times before. The only question I found has ...
4
votes
6answers
358 views

Order of subject and modifiers in variable names

I'm looking for experiences regarding the ordering of the subject and modifiers in variable names. A simple object Shape would have just a subject for the variable name, such as Area. A slightly ...
7
votes
5answers
563 views

Discussions of simplicity

Recently at my company we've had a bit of a debate about abstraction vs. simplicity. One school of thought I'd characterize as "DRY and abstraction can do no harm," and leads to code like this: def ...
26
votes
2answers
15k views

What's wrong with relative imports in Python?

I recently upgraded versions of pylint, a popular Python style-checker. It has gone ballistic throughout my code, pointing out places where I import modules in the same package, without specifying ...
8
votes
4answers
2k views

Are fluent interfaces more flexible than attributes and why?

In a EF 4.1 Code First tutorial the following code is given: public class Department { public int DepartmentId { get; set; } [Required] public string Name { get; set; } public virtual ...
0
votes
2answers
1k views

GUI advice for a responsive touchscreen

I am tasked with building a piece of software that interfaces with a MySQL database, in order to allow the user to pick songs to play and que using a touch screen, and then they are shown ...
7
votes
6answers
1k views

Indentation: is there any evidence to show whether 2 or 4 spaces is more readable? [closed]

At the company I work for, we're trying to standardize our development practices, and we want to make the right call regarding indentation. Is there any empirical evidence (preferably research ...
-1
votes
2answers
326 views

How to mix different styles of programming on several languages?

I know that Senior Developer doesn't use only one language and only one platform or IDE. Can you advise how to mix different styles of programming to make efficient code? For example, best mixing is ...
5
votes
2answers
662 views

Should you create a class within a method?

I have made a program using Java that is an implementation of this project: http://nifty.stanford.edu/2009/stone-random-art/sml/index.html. Essentially, you create a mathematical expression and, ...
1
vote
4answers
259 views

Is 'Protection' an acceptable Java class name

This comes from a closed thread at stack overflow, where there are already some useful answers, though a commenter suggested I post here. I hope this is ok! I'm trying my best to write good ...
9
votes
5answers
796 views

Zero as a constant?

I have come across this programming idiom recently: const float Zero = 0.0; which is then used in comparisons: if (x > Zero) {..} Can anyone explain if this is really any more efficient or ...
9
votes
6answers
12k views

Single quotes vs double quotes [closed]

I just started a job where I'm writing Python after coming from a Java background, and I'm noticing that other developers tend to quote strings using single quotes ('') instead of double quotes (""). ...
12
votes
5answers
583 views

Reformatting and version control

Code formatting matters. Even indentation matters. And consistency is more important than minor improvements. But projects usually don't have a clear, complete, verifiable and enforced style guide ...
33
votes
16answers
4k views

Should I continue my self-taught coding practice or learn how to do coding professionally? [closed]

Lately I've been getting professional work, hanging out with other programmers, and making friends in the industry. The only thing is I'm 100% self-taught. It's caused my style to extremely deviate ...
7
votes
9answers
2k views

Is it any good to use binary arithmetic in a C++ code like “C style”?

I like the fact that the C language lets you use binary arithmetic in an explicit way in your code, sometimes the use of the binary arithmetic can also give you a little edge in terms of performance; ...
8
votes
3answers
269 views

How to get feedback from the community on large chunks of code?

Code Review.SE is great when you need feedback on a precise, short piece of code. But where to get similar feedback about the code itself when: you have thousands of LOC, don't have colleagues in ...
1
vote
6answers
2k views

Setters or constructor for many variables? [duplicate]

Possible Duplicate: Are there guidelines on how many parameters a function should accept? I have got class with 30 variables (it is application form), so I wonder what is the best practice ...
7
votes
4answers
435 views

Warn about 3rd party methods that are forbidden

Note: This question refers to code written in Java or C#. I am managing a couple of large projects where we have discovered issues (not necessarily bugs) with some 3rd party/SDK methods and have ...
4
votes
3answers
2k views

When to write an explicit return statement in Groovy?

At the moment I am working on a Groovy/Grails project (which I'm quite new in) and I wonder whether it is good practice to omit the return keyword in Groovy methods. As far as I know you have to ...
7
votes
4answers
4k views

Anonymous function vs. separate named function for initialization in jquery

We just had some controversial discussion and I would like to see your opinions on the issue: Let's say we have some code that is used to initialize things when a page is loaded and it looks like ...
3
votes
4answers
295 views

Create new variable or make multiple chained calls?

What is the best way to get this attributes, thinking in performance and code quality? Using chained calls: name = this.product.getStock().getItems().get(index).getName(); id = ...