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

learn more… | top users | synonyms (1)

21
votes
2answers
11k 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 ...
7
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
313 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
541 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, ...
0
votes
4answers
253 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
790 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 ...
8
votes
6answers
9k 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
546 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
1k 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
264 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
1k 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
416 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
1k 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 ...
6
votes
4answers
3k 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
290 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 = ...
8
votes
2answers
321 views

How to deal with ad-hoc mindsets?

I joined a dev team of six two month ago. People are nice, all is good. But more and more I observe an ad-hoc mindset. Stuff gets quick fixed, at the cost of future usability, there is little testing ...
1
vote
4answers
552 views

Indenting labels in C

I noticed that in the Vim automatically indents labels in a rather unintuitive way (IMHO). int main(void) { goto end; end: return 0 } Are there any style guidelines for labels? For the ...
8
votes
5answers
582 views

Is it customary to write Java domain objects / data transfer objects with public member variables on mobile platforms?

We performed a code review recently of mobile application Java code that was developed by an outside contractor and noticed that all of the domain objects / data transfer objects are written in this ...
10
votes
4answers
2k views

How do you keep code with continuations/callbacks readable?

Summary: Are there some well-established best-practice patterns that I can follow to keep my code readable in spite of using asynchronous code and callbacks? I'm using a JavaScript library that ...
10
votes
7answers
787 views

Are More Comments Better in High-Turnover Environments?

I was talking with a colleague today. We work on code for two different projects. In my case, I'm the only person working on my code; in her case, multiple people work on the same codebase, including ...
5
votes
3answers
293 views

Should I return iterators or more sophisticated objects?

Say I have a function that creates a list of objects. If I want to return an iterator, I'll have to return iter(a_list). Should I do this, or just return the list as it is? My motivation for returning ...
32
votes
8answers
1k views

When using method chaining, do I reuse the object or create one?

When using method chaining like: var car = new Car().OfBrand(Brand.Ford).OfModel(12345).PaintedIn(Color.Silver).Create(); there may be two approaches: Reuse the same object, like this: public ...
2
votes
3answers
546 views

Is there a faster way to work out this logic?

The purpose of this assignment was the find the smallest and largest of the integer(User inputs 5 entries) I am a beginner Java programmer with no prior experience. Is there an easier way to do this ...
49
votes
17answers
5k views

Working on someone else's code

I have hardly a year's experience in coding. After I started working, most of the time I would be working on someone else's code, either adding new features over the existing ones or modifying the ...
57
votes
16answers
4k views

Is inconsistent formatting a sign of a sloppy programmer?

I understand that everyone has their own style of programming and that you should be able to read other people's styles and accept it for what it is. However, would one be considered a sloppy ...
1
vote
3answers
4k views

how to nicely use constant std::string in c++

In my current code project, there is an awful lot of constant strings I use to print out error messages. Hardcoding such strings is generally considered to be bad practice. Now I'm searching for a ...
5
votes
3answers
483 views

Style for control flow with validation checks

I find myself writing a lot of code like this: int myFunction(Person* person) { int personIsValid = !(person==NULL); if (personIsValid) { // do some stuff; might be lengthy int myresult ...
9
votes
2answers
982 views

Is this awkward spacing some type of style?

In reading another programmers code, he uses a format I have never seen. E.G. namespace MyNs.HereWeAre {//tab here for some reason public class SomeClass ...
2
votes
4answers
291 views

Linking in code comments (to other unique anchors/comments)

How would you recommend creating "anchors" in code comments, so that during maintenance, developers can easily cross-reference other code comments. I realise that software should be intelligently ...
11
votes
6answers
1k views

A defense for boilerplate?

To me, boilerplate code is obviously bad. However I've met a developer who displays resistance in any attempt to reduce boilerplate. I realized I didn't have a readily formed, well thought out ...
9
votes
3answers
3k views

When to use typedef?

I'm a bit confused about if and when I should use typedef in C++. I feel it's a balancing act between readability and clarity. Here's a code sample without any typedefs: int ...
3
votes
5answers
2k views

Alternative IDEs [closed]

After seeing http://www.kickstarter.com/projects/ibdknox/light-table I'm wondering if anyone has come across other alternative methods of developing. When working on embedded things Notepad++ was ...
5
votes
7answers
342 views

Which style is better to check and log the error?

I have read some code and here are two ways to check and log the error in cpp code that repeats in my project many times. Which way is better? 1. bool AClass::myMethod() { if (!SomeCondition()) ...
12
votes
10answers
3k views

Passing member variable as a method parameter

In a project, I've found a code like this: class SomeClass { private SomeType _someField; public SomeType SomeField { get { return _someField; } set { _someField = value; ...
14
votes
5answers
5k views

Should a string constant be defined if it's only going to be used once?

We're implementing an adapter for Jaxen (an XPath library for Java) that allows us to use XPath to access the data model of our application. This is done by implementing classes which map strings ...
61
votes
17answers
4k views

Recommendations for teaching junior programmers good coding style

I am a big fan of good coding style, producing clean, clear code that runs well and is easy to use and integrate into larger systems. I believe that we programmers are essentially craftspeople who ...
0
votes
2answers
187 views

Where can I find language specific programming standards and style guides?

Is there a good source of best practices, programming standards and coding styles for different languages, specifically Ruby and Javascript?
6
votes
5answers
607 views

Are SQL Injection vulnerabilities in a PHP application acceptable if mod_security is enabled?

I've been asked to audit a PHP application. No framework, no router, no model. Pure PHP. Few shared functions. HTML, CSS, and JS all mixed together. I've discovered numerous places where SQL injection ...
-1
votes
2answers
209 views

How should I group these variables?

I have a shape that will be defined by: char s_type; char color; double height; double width; These variables are scanned in from a request string sent to my server and passed into my printing ...
5
votes
3answers
559 views

What are the names for various forms of camel-case style naming?

For the purposes of communicating coding styles to my co-workers, what would I formally call the following variants of camel case? camelCase and CamelCase Notice that the former version ...
28
votes
10answers
3k views

I can't program because the code I am using uses old coding styles. Is this normal to programmers?

I have my first real job as programmer, but I can't solve any problems because of the coding style used. The code here: Does not have comments Does not have functions (50, 100, 200, 300 or more ...
0
votes
6answers
267 views

Function parameter names

I just found the following code in our code base: public String identifyArchitectureName(String platformName, String input) ... In my opinion input is one of the most meaningless names for a ...
8
votes
5answers
2k views

Any Practical Alternative to the Signals + Slots model for GUI Programming?

The majority of GUI Toolkits nowadays use the Signals + Slots model. It was Qt and GTK+, if I am not wrong, who pioneered it. You know, the widgets or graphical objects (sometimes even ones that ...
20
votes
10answers
1k views

Are nullable types preferable to magic numbers?

I have been having a little bit of a debate with a coworker lately. We are specifically using C#, but this could apply to any language with nullable types. Say for example you have a value that ...
20
votes
6answers
2k views

Why the recent shift to removing/omitting semicolons from Javascript?

It seems to be fashionable recently to omit semicolons from Javascript. There was a blog post a few years ago emphasising that in Javascript, semicolons are optional and the gist of the post seemed to ...
5
votes
8answers
748 views

creative & complex vs simple and readable

Which is a better option? It's not always that when you have something creative your code is going to look ugly. But at times it does go a bit ugly. e.g. if ( (object1(0)==object2(0) && ...
23
votes
7answers
10k views

Practical considerations for HTML / CSS naming conventions (syntax) [closed]

Question: what are the practical considerations for the syntax in class and id values? Note that I'm not asking about the semantics, i.e. the actual words that are being used, as for example ...