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

learn more… | top users | synonyms (1)

-1
votes
0answers
71 views

Redundant ElseIf-Else Blocks

These types of if-elseif-else blocks appear all over the place, and in no small number (so the less the better). Every time I have to think and decide: Do I want the simpler or the more thorough of ...
-4
votes
0answers
42 views

Custom code folding in Eclipse

For those who use Eclipse and are working primarily in Java, there is a custom folding plugin coffee script. It is old but still works. However, C/C++ users are left without code folding ...
0
votes
1answer
40 views

Using the optional 'self' reference in instance methods in Swift as a matter of style

Swift allows optional prefixing of method calls and property references to the current object instance via self. Removing these prefixes can declutter code but, depending on the length of the method ...
0
votes
2answers
73 views

PHP conditional test func call against two values

I was wondering if there's a one liner for PHP that would allow me test multiple values against a function call. As example, say I want to test if foo() returns either 1 or 2, (in pseudo code) if( ...
-1
votes
3answers
154 views

Cleaner C# without unneeded indents [closed]

In OO languages, at least C#, everything has to be in a class. Sometimes, everything is in a namespace as well. Just about literally all the code in one class is going to be automatically indented ...
4
votes
1answer
152 views

Why is the use of JavaScript in HREF attributes discouraged?

Disclaimer: I came to Programmers.SE to ask this question because I understand this is the place to ask this type of question, and not necessarily stackoverflow. If I am wrong, please close the ...
0
votes
0answers
40 views

type name for state machine state (as opposed to other state variables)

I need to create a typedef for a state machine state, e.g. enum ToasterStateMachineState { TSM_READY, TSM_TOASTING, TSM_DONE }; But ToasterStateMachineState seems verbose and redundant; is ...
3
votes
1answer
107 views

Should a class explicitly implement interface if its superclass also implements it?

Given an interface interface I { one(); two(); } An abstract base class partially implementing I abstract class A { @Override void one() { //something } } And lastly ...
7
votes
5answers
730 views

Coding style issue: Should we have functions which take a parameter, modify it, and then RETURN that parameter?

I'm having a bit of a debate with my friend over whether these two practices are merely two sides of the same coin, or whether one is genuinely better. We have a function which takes a parameter, ...
0
votes
2answers
85 views

Print Statements Inside Function Or Before Calling It? [closed]

I have a script which different people may use. I have print statements so people can follow along what the script is doing, and if it breaks where it went wrong, and if a certain step takes a long ...
2
votes
2answers
198 views

At what point should you collapse many parameters into (e.g.) struct to improve readability in function headers?

While making a struct creates some overhead at run-time, packaging a bunch of frequently-used-together variables can dramatically increase code readability. How do you balance the two? I was just ...
2
votes
3answers
409 views

Should one value simpler code over performance when returning multiple values?

I'm too often facing situations where I need to get several types of information from a method. I usually think long and hard to circumvent these situations but I'm thinking it's pointless work that ...
0
votes
0answers
76 views

Improving the speed of coding in Fortran [duplicate]

I've got about 1.5 years of experience in writing Fortran 2003 codes for scientific applications (duh), and I'm finding myself now in the situation in which I need to write working code as fast as ...
6
votes
2answers
500 views

Which is a better pattern (coding style) for validating arguments - hurdle (barrier) or fence? [duplicate]

I don't know if there are any accepted names for these patterns (or anti-patterns), but I like to call them what I call them here. Actually, that would be Question 1: What are accepted names for these ...
15
votes
16answers
1k views

Do else blocks increase code complexity? [closed]

Here is a very simplified example. This isn't necessarily a language-specific question, and I ask that you ignore the many other ways the function can be written, and changes that can be made to it.. ...
2
votes
1answer
123 views

RefactorException: Good idea or bad idea?

When I'm doing large scale refactors I'm often commenting out the contents of methods and using NotImplementedExceptions for stuff that I still need to refactor. Problem is that this is interfering ...
0
votes
1answer
128 views

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

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 ...
0
votes
1answer
127 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
148 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 ...
0
votes
4answers
296 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
5answers
283 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
73 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
75 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 ...
6
votes
2answers
424 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
3answers
429 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
2answers
114 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 ...
-3
votes
1answer
326 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 ...
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 ...
2
votes
1answer
91 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; ...
41
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
1answer
122 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 ...
5
votes
11answers
514 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 ...
-2
votes
3answers
187 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?
1
vote
1answer
140 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 = ...
3
votes
4answers
270 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 ...
3
votes
1answer
198 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
456 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
96 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
107 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 ...
6
votes
0answers
335 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
59 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(); ...
2
votes
1answer
184 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) ...
4
votes
3answers
171 views

Organization of DLL linked functions

This is a code organization question. I got my basic code working but when I expand it, it will be terrible. I have a DLL which I don't have a .lib for. Therefore I have to use the whole ...
1
vote
1answer
93 views

Is there an easy way to type in common math symbols?

Disclaimer: I'm sure someone is going to moan about easy-of-use, for the purpose of this question consider readability to be the only factor that matters So I found this site that converts to easting ...
1
vote
1answer
161 views

The purpose of using a constants pool for immutable constants

Originally posted at stackoverflow.com/q/23961260 I come across the following code with a lot of frequency: if (myArray.length == Constants.ZERO_INT) or if (myString != null && ...
1
vote
3answers
306 views

Use unnamed object to invoke method or not?

If I have a class with only only public method. When I use this class, is it good to use unnamed object to invoke its method? normal: TaxFileParser tax_parser(tax_file_name); auto content = ...
2
votes
4answers
157 views

Should our team order Javascript class methods/properties consistently? If so, how?

As our team is growing I've noticed that different developers put their class methods in different orders. For instance: var Foo = Backbone.Model.extend({ someVar: {}, initialize: ...
31
votes
3answers
917 views

Origins of code indentation

I am interested in finding out who introduced code indentation, as well as when and where it was introduced. It seems so critical to code comprehension, but it was not universal. Most Fortran and ...
-1
votes
1answer
271 views

_variable - why that underscore at the beginning? [closed]

Sometimes I see people writing variable names like this: int _variable; IMO That's really ugly. What's that about?
4
votes
4answers
587 views

Is lack of whitespace a sign of a cargo cult programmer? [closed]

Eric Lippert has written about cargo cult programming, and Steve McConnell has tackled the subject from a Software Engineering point of view. Eric provides a fairly succinct description: They ...