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

learn more… | top users | synonyms (1)

0
votes
9answers
3k views

Line break before/after operator

While Sun's Java code convention suggests to put line break before the operator many other guidelines disagree with it. I do not see any obvious pros and cons, so are there advantages of using one of ...
-4
votes
0answers
25 views

How to store, list, open files to MySQL using C# [on hold]

Im creating a c# employee app, I've created a form for Employee files and I dont have any idea how to store list and open files to mysql with c#. Any help with detailed example will be aprociated! ...
-1
votes
1answer
69 views

Pros and cons of using generic delegates as nested functions

I've written code like this before: private void Strings_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { var onAdd = new Action(() => { if(e.NewItems != ...
0
votes
1answer
67 views

if else brackets on same line, best comment style? [on hold]

I used to do this: // If the cat is black if ( $catColor == 'black' ) { ... } // Otherwise eat a taco else { ... } But I've more recently started to move toward this style of conditional ...
17
votes
12answers
2k views

Correct comment to put for boolean function arguments that are “false”?

From some open source projects, I gathered the following coding style void someFunction(bool forget); void ourFunction() { someFunction(false /* forget */); } I always have doubt about what ...
0
votes
3answers
379 views

Eliminate duplicate code in nested IFs without creating a function [duplicate]

Let's say we have two ifs that depend on each other: if var exists { if var is array { //Do stuff with var } else { //Resolve the problem } } else { //Resolve the ...
0
votes
3answers
173 views

Overloading Methods With Different Behavior - Style

I have a style question about overloading methods/constructors. I have a constructor which does something very simple, and then calls a method with some side effects. Sometimes however I don't want ...
0
votes
0answers
112 views

Thoughts on full-line separators in code? [closed]

Personally, I like having separators between methods/classes in my code. I think it greatly increases readability and you get a faster overview of the code. However, from looking at open-source code ...
0
votes
0answers
12 views

JavaScript Print Formatting [migrated]

I'm learning NodeJS and rewriting some code to see how it compares. For one script, I am trying to take dates in the form of strings and turn them into JavaScript Date objects to perform calculations ...
0
votes
2answers
152 views

How to systematize tagging in code? [closed]

There are several almost standard tags used in comments: FIXME, TODO, BUGBUG. Which other tags do you use and for what? Are there any standards on using them, i.e. format (supplementing with date ...
-2
votes
7answers
336 views

Vector operations: vec1.dot(vec2) vs vec1 * vec2 vs dot(vec1, vec2) [closed]

What's your preferred way to implement/use vector operations? vec1.dot(vec2) allows to reuse vec1 but is hard to read for longer equations dot(vec1, vec2) A friend of mine prefers this as "dot" ...
1
vote
4answers
273 views

How can if (sscanf(buf, “%i”, &mode) != 1 || TRUE) be rewritten to if (TRUE)?

I got lost in the opening of this post on reddit. How can if (sscanf(buf, "%i", &mode) != 1 || TRUE) be rewritten to if (TRUE)? Does this assume that the sscanf never fails?
0
votes
1answer
91 views

Checking negative of a condition

What is the (slightly pejorative) term for checking the negative of a condition (rather than the positive which is often more readable): e.g. if(!someVar) { return null; } else { return ...
1
vote
2answers
109 views

Should I sacrifice code succintness to ensure the narrowest variable scope? [duplicate]

In many languages (e.g. both Perl and Java - which are the two languages I work most with) it is possible to narrow the scope of local variables by declaring them within a block. Although it adds ...
46
votes
6answers
20k views

Why is trailing whitespace a big deal?

Trailing whitespace is enough of a problem for programmers that editors like Emacs have special functions that highlight it or get rid of it automatically, and many coding standards require you to ...
55
votes
12answers
11k views

What is the ideal length of a method? [closed]

In object-oriented programming, there is no exact rule on the maximum length of a method , but I still found these two qutes somewhat contradicting each other, so I would like to hear what you think. ...
2
votes
4answers
527 views

Coding convention regarding the usage of underscores [closed]

There seems to be divided opinion on this subject, and I wanted to get people's insights on whether they've found using underscore prefixes and suffixes to be helpful with coding or not. You know, ...
6
votes
7answers
520 views

Commenting regular expressions

Are there any common practises for commenting the regular expressions: inline comments referring different part of RegEx or general comment for all expression?
6
votes
3answers
692 views

Is it bad idea to use flag variable to search MAX element in array?

Over my programming career I formed a habit to introduce a flag variable that indicates that the first comparison has occured, just like Msft does in its linq Max() extension method implementation ...
0
votes
5answers
258 views

Should we only catch in exceptional circumstances?

Whether error handling by throwing exceptions is good or bad is contentious. Are exceptions as control flow considered a serious antipattern? If so, Why? The common line is that exceptions are for ...
1
vote
0answers
54 views

MVC Controller - keeping methods small

I'm reading uncle Bob's Clean Code and it completely revolutionizes my programming style. In this book author claims that best methods are small methods. What about controller's action methods in ...
0
votes
2answers
47 views

Erlang return value conventions

Should functions that return tuples, always return tuples? For example, I have a function is_user_name_allowed that returns a tuple in this he form if the username is not allowed: {false, ["Reason ...
36
votes
14answers
5k views

How important is it to clean up someone else's code when faced with a tight deadline? [closed]

(I'm talking about HTML / CSS code (not programming languages) but I think we also face the same issue as with programmers.) I am the senior front-end designer in a team and I often have to re-work ...
40
votes
6answers
3k views

Is making a small change, testing it, then “rinse and repeat”, a bad habit?

I am a programmer with a number of years of experience. I realized I got a certain habit. I'm not sure whether it's really a bad habit or not. I get a list of tasks to perform for a solution, even ...
1
vote
2answers
390 views

How to set up something like an integration server that measures the quality of code and reject the code if the score is below a certain number?

Even if I don't like enforcing people to do things (and I believe that it may decline the productivity and cause anger), I really want to enforce good coding style. Is there a way to set up ...
6
votes
2answers
314 views

C programming practice, passing a pointer to a function [closed]

Consider the following C function which takes as argument a string, which is then stored inside a struct: struct mystruct* usestring(char* string) { struct mystruct *struct; struct = ...
0
votes
2answers
108 views

Where are C variables declared [duplicate]

I see a lot of code with variables declared right after the function, but when I post something like that people end up mad and say it is better to declare them when they are used. I assume this all ...
5
votes
4answers
2k views

Should you ever use private on fields and methods in C#?

I am somewhat new to C# and just found out that: in C# all of the fields and methods in a class are default private. Meaning that this: class MyClass { string myString } is the same as: class ...
-3
votes
1answer
297 views

Why is the JavaScript-language different in different programs/sites? [closed]

I'm kind of new to programming and i have a question that's been bothering me for awhile. Why is the JavaScript-language different in different programs/sites. I've used Codecademy to practice and ...
2
votes
1answer
84 views

Is this approach to CSS correct?

Reading SASS basic features on their website, I stumbled upon the @extend feature. The example they give is the following: .message { border: 1px solid #ccc; padding: 10px; color: #333; ...
5
votes
11answers
436 views

Is too much whitespace a bad thing? [closed]

I'm often told by my friends and colleagues that I use way to much whitespace. I guess I do use a little too much whitespace. I often add a line break almost after every line and large blocks of ...
7
votes
4answers
921 views

css - use universal '*' selector vs. html or body selector?

Applying styles to the body tag will be applied to the whole page, so body { font-family: Verdana } will be applied to the whole page. This could also be done with * {font-family: Verdana} ...
0
votes
1answer
72 views

Inheriting from Abstract class vs Enum Types for custom exceptions

I am creating an interface and would like the implementer(s) of this interface to throw exceptions in the case that something goes wrong. Let's call the implementer a plugin. I have a director which ...
1
vote
1answer
134 views

Object Chain through an Interface

Say I have 3+ types of objects: function Sea() { var logs = [Logs]; this.getLog = function(ind){return logs[ind]} } function Log() { var bumps = [Bumps]; this.getBump = ...
14
votes
2answers
11k views

What is the difference between K&R and One True Brace Style (1TBS) styles?

I have read the Wikipedia article on Indent Styles, but I still don't understand. What is the difference between K&R and 1TBS?
-2
votes
3answers
182 views

Is there an official programming format? [closed]

A person can make their code readable and neat in their own way. However, is there a standard programming format that professional programmers are compliant to?
15
votes
16answers
3k views

Coding standards and coding style, is it that much important? [closed]

There are a lot of ways of typing code, but I can't understand what is the good reason to adopt a certain standard or style if it does not change the way the code can be read and understood. Everyone ...
3
votes
4answers
231 views

Improve coding quality

I have been dealing with programming for several years now (I am still a student but with a lot of internships). Mostly working with C++, Python and MATLAB, I noticed that whenever I download an SDK ...
67
votes
19answers
22k views

Are `break` and `continue` bad programming practices?

My boss keeps mentioning nonchalantly that bad programmers use break and continue in loops. I use them all the time because they make sense; let me show you the inspiration: function verify(object) ...
3
votes
1answer
168 views

How reduce the usage of Magic Strings?

In the application database there is a configuration table with this schema: Table: ReleaseProperty ReleasePropertyID ReleaseID Name Value Currently to retrieve a specific property I pass to the ...
3
votes
3answers
399 views

Refactoring previous intern's noodle code with future interns in mind [duplicate]

Background I've run across this problem as I am currently an intern at a large company's local software division. I have been given the task of extending a project that several previous interns have ...
0
votes
1answer
62 views

Loading dynamic css based on user

I want to provide different UI theme based on user who logged in. For that I have came up with following 2 options: create separate files for all themes duplicating all the common css. This way I ...
2
votes
2answers
106 views

Should special (simpler) cases have separate code paths?

I have a rather complex method which can get called in two possible "scenarios". One is a special case of the other in which all the nested foreach loops are only executed once and several if ...
18
votes
5answers
870 views

Are there any scientifically rigorous studies of coding style principles?

Is a coding style principle - e.g. the single-exit principle - really a good thing? Always, or just sometimes? How much difference does it really make? Whatever your opinions, these are obviously ...
6
votes
1answer
266 views

How to manage a relatively large one-man project? [duplicate]

I am basically working on https://github.com/KirisurfProject/ entirely alone. This is around 4000 lines of Go code, plus around 1000 lines of Racket (a Lisp) code for the GUI part; the equivalent in ...
1
vote
2answers
56 views

Alias variable vs multiple use of getter

Would you rather: $this->getDoctrine()->getManager()->persist($currency); $this->getDoctrine()->getManager()->persist($user); $this->getDoctrine()->getManager()->flush(); ...
14
votes
8answers
5k views

Using JOIN keyword or not

The following SQL queries are the same: SELECT column1, column2 FROM table1, table2 WHERE table1.id = table2.id; SELECT column1, column2 FROM table1 JOIN table2 ON table1.id = table2.id; And ...
2
votes
1answer
139 views

Is serialization better done in instance methods or static methods

Say I have a class workStockItem, that I wish to serialize. Which is the better style? using a static method or using a non-static method (maybe even implemented as a property as seen below) ...
94
votes
22answers
6k views

Elegant ways to handle if(if else) else

This is a minor niggle, but every time I have to code something like this, the repetition bothers me, but I'm not sure that any of the solutions aren't worse. if(FileExists(file)) { contents = ...
67
votes
11answers
4k views

Never use Strings in Java? [closed]

I stumbled upon a blog entry discouraging the use of Strings in Java for making your code lack semantics, suggesting that you should use thin wrapper classes instead. This is the before and after ...