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

learn more… | top users | synonyms (1)

-5
votes
0answers
26 views

Naming convention to be used in web development? [on hold]

Would you suggest best/most commonly used naming conventions to be followed for HTML ids,classes and names JavaScript functions PHP.
6
votes
2answers
436 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 ...
14
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
119 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 ...
-1
votes
1answer
80 views

Pros and cons of using generic delegates as nested functions [closed]

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
92 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
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
1answer
108 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
123 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
289 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
264 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
58 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
55 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
329 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
394 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
110 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
302 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
85 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; ...
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 ...
0
votes
1answer
79 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
443 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
183 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
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 = ...
3
votes
4answers
246 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
181 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
417 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
65 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 ...
6
votes
1answer
288 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
57 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
143 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) ...
3
votes
3answers
164 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
87 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
127 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
146 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
146 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
896 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
265 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?
3
votes
4answers
545 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 ...
2
votes
4answers
853 views

Identify this programming style

Some of the legacy code I've inherited uses the fact that C# supports multiple assignment to write code like: void DisableControls() { ddlStore.Enabled = ddlProgram.Enabled ...
1
vote
2answers
395 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 ...
1
vote
2answers
385 views

Objective-C style: Do I implement factory methods or init methods?

I'm new to Objective-C programming, and creating various classes for an iOS application I'm working on. When creating objects, it seems like many classes in the built-in frameworks use the "static ...
4
votes
2answers
231 views

Using a closure to avoid code duplication in Python

Sometimes I find myself wanting to run the same code from a few different spots in the same function. Say I have some function func1, and I want to do the same thing from a few different spots in ...
1
vote
4answers
608 views

What is “using namespace” pollution?

I was looking at the google coding guide [here] and they do not recommend that one use the using namespace ornamespace:function` - if I did not misinterpret it. Does this apply to std as well? ...
2
votes
1answer
93 views

equivalence in callback and non-callback javascript

I'm pretty sure that the following two snippets are equivalent but I wanted to double check: CALLBACK STYLE function foo(input, callback) { // do stuff with input callback(); } function ...
14
votes
2answers
584 views

Creating nested functions for purely aesthetic reasons?

I've always wondered what other programmers think about the idea of creating pure aesthetic functions. Say I have a function that processes a chunk of data: Function ProcessBigData. Say I need ...
-2
votes
1answer
110 views

Is there a named antipattern for unclear API not exposing the requirements? [closed]

In the source code I'm evaluating (jarjar), there exists java code that can be used like this: JarJarTask fixture = new JarJarTask(); fixture.addConfiguredRule(new Rule()); fixture.execute(); Which ...
1
vote
1answer
386 views

How to break these long C++ lines in a neat way? [closed]

I'm on my first bigger C++ project and find that I have some really long lines. My goal is to break them to 79 columns, but I do not really know how to do this in a neat way. Are there some guidelines ...
25
votes
5answers
3k views

Why is it bad to write something in language X as if you're writing a program in language Y in terms of using a shared coding paradigm [closed]

A while ago, I asked a question on SO about something written in C++, but instead of getting an answer to the problem at hand, the comments went all crazy on my coding style, even when I indicated ...