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

learn more… | top users | synonyms (2)

1
vote
1answer
23 views

Terms to differentiate between internally-visible and user-visible errors

In my code I often need to differentiate between messages intended for logging and those displayed to users. I'm looking for a terse term for naming variables and methods that indicates a ...
150
votes
19answers
46k views

Should I return from a function early or use an if statement? [closed]

I've often written this sort of function in both formats, and I was wondering if one format is preferred over another, and why. public void SomeFunction(bool someCondition) { if (someCondition) ...
-1
votes
0answers
59 views

Removing optional braces in code [on hold]

Is there any regex I can use to strip optional braces from code written in curly-brace programming languages? I'd like to follow the K&R style, where braces only appear where necessary. ...
0
votes
2answers
57 views

Literals versus instantiating by name lists and dicts in Python?

In Python, what is the difference in these declarations… my_list = [] my_list = list() …and in these? my_dict = {} my_dict = dict() Are they interpreted the same, and why would you use one over ...
-4
votes
2answers
106 views

Should one always start a boolean with “is” or “has”? Or write it as it makes more sense grammatically?

Examples: isKeyValid -> keyIsValid hasPostThumbnail -> postHasThumbnail The first case is easier to remember (convention). The second is easier/more natural to read. Which should I use?
2
votes
1answer
37 views

Code style for parse-methods in Scala?

Say I have a class with multiple parameters: case class Foo(a: String, b: String, c: String, d: String, ... ) Now say I want to parse an instance of Foo from a Map[String, String]: // returns ...
28
votes
13answers
4k views

Is coding style in organizations an optional thing?

This programming style document has a general rule, that says : The rules can be violated if there are strong personal objections against them. This collides with the way I am thinking, and ...
1
vote
1answer
93 views

Understanding recursive solution of some algorithm

Most of the time we need to understand someone else' code for example I am studying Graph Algorithms from Sedgewick's online resources, the particular code example is taken from cycle detection ...
2
votes
2answers
43 views

When should the naming of data structures be more abstract or literal?

Say that I create an ordered set structure, and I choose to implement it as a binary tree. I name my structure OrderedSet because I feel its underlying implementation isn’t necessarily important to ...
4
votes
2answers
88 views

Common loop variable names for indexes in 4D and above

I am curious if there are common loop index variables (of single character or not) for dealing with 4 dimensions and above? I was helping another student working through CS50x who was just learning ...
4
votes
1answer
114 views

Is there something to be said for putting the “default” case of a switch statement first?

Like: switch (value) { default: something_common() case 1: niche_case() ... } etcetera. if-else statements require an "if" first and an "else" last, but switch statements are more flexible ...
5
votes
2answers
95 views

Where to put the Angular app in a ASP.NET Web API solution?

I'm starting a greenfield app and I want to use ASP.NET (4.6) and Angular 2. For the backend I have created a project in Visual Studio, and now I'm wondering where to put the Angular app. I really ...
-2
votes
2answers
116 views

Are there coding standards for whether procedural programs should have source code listed top-down or bottom-up? [closed]

Let's say I have a basic procedural program which is well structured into decomposed functions. For example, a main() function which calls functions a and b, which in turn each call functions c and d, ...
-2
votes
1answer
122 views

Is this unprofessional when “Wappalyzer” sees all my technology? [closed]

After I installed "Wappalyzer", extension wich display technology, wich site using. I checked many sites and in most of cool projects, like "Youtube", "Github","stackoverflow" etc, wappalyzer display ...
3
votes
2answers
166 views

Using “partial” type to shorten main class file

Is it a normal practice, or a sign of a bad design? For example I have a function that loads prefabs in a main logic class nearing 200 lines, and I can either move it out into a separate file ...
2
votes
2answers
97 views

It it a better to have the expected return at the beginning or at the end of a function?

This is a function that searches child nodes recursively until it finds one that is a text: _.findPrevText = (node) => { if (node.nodeType === 3) return node return ...
6
votes
3answers
3k views

Is relying on implicit argument conversion considered dangerous?

C++ has a feature (I cannot figure out the proper name of it), that automatically calls matching constructors of parameter types if the argument types are not the expected ones. A very basic example ...
112
votes
23answers
15k 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 = ...
4
votes
1answer
51 views

Common imports between many scripts in Python project

I'm writing an automated installation script for a bunch of software, in Python. The purpose is for the script to fetch compressed files from a directory and install/configure each utility or ...
3
votes
4answers
232 views

When should a function take a pointer for a collection to fill vs returning a pointer with a filled collection?

In C++ I frequently see these two signatures used seemingly interchangeably: void fill_array(Array<Type>* array_to_fill); Array<Type>* filled_array(); I imagine there is a subtle ...
2
votes
1answer
99 views

Is it bad practice to name a class with a facade suffix?

Is it bad practice to name classes after the façade pattern? public class OrderFacade {} public class InvoiceFacade {} public class ThingFacade {} ... These classes do follow the Façade pattern.
20
votes
8answers
5k views

What Style is Better (Instance Variable vs. Return Value) in Java

I often find myself struggling to decide which of these two ways to use when I require to use common data across some methods in my classes. What would be a better choice? In this option, I can ...
17
votes
6answers
12k 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 ...
9
votes
3answers
276 views

OOP design problem. Two kinds of empty Optional

I'm writing a quite simple application that deals with hotel rooms reservation. I've got a problem at one stage. I'm processing a queue of orders. For every order one of the receptionists should ...
26
votes
17answers
1k views

Dealing with co-workers who do not have a consistent coding style?

What do you when you're working with someone who tends to write stylistically bad code? The code I'm talking about is usually technically correct, reasonably structured, and may even be ...
1
vote
2answers
75 views

TypeScript/ES2015: Prefer `const` instead of `let` reduces readability?

ES2015 introduced the let and const keywords, which essentially have the same semantics apart from reassignment. (const can be seen as a final variable in languages like Java.) I see the point of ...
1
vote
3answers
96 views

Single exit point meets Java streams

We currently have a sensitive discussion going in the company that touches on a couple of old primary opinion based discussions. Nevertheless, I would like to discuss the case in this forum to ...
14
votes
3answers
267 views

Duplicating constants between tests and production code?

Is it good or bad to duplicate data between tests and real code? For example, suppose I have a Python class FooSaver that saves files with particular names to a given directory: class ...
6
votes
4answers
228 views

Is using nested function calls a bad thing?

In a recent homework assignment I ended up calling my functions in an ugly way uglyReceipt(cashParser(cashInput())) the program itself worked perfectly but I still felt like I was doing something ...
-1
votes
2answers
76 views

Should we embed special cases into business logic/algorithm or leave it separate? [closed]

Consider I have some codes that use different logic for some special case, e.g.: bool compareRatio(unsigned int a,unsigned int b,unsigned int x,unsigned int y){ if(x==0){ return false; ...
11
votes
2answers
472 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 ...
0
votes
2answers
68 views

Why is the _replace method of Python namedtuple classes protected?

In the section Method Names and Instance Variables, the Python Style Guide (aka PEP 0008) says, "Use one leading underscore only for non-public methods and instance variables." Why then, does the ...
57
votes
5answers
7k views

Why are large amounts of magic numbers acceptable in CSS and SVGs?

Often times I see questions on the Hot Network Questions list like this that basically ask "how do I draw this arbitrary shape in CSS". Invariably the answer is a couple of blocks of CSS or SVG data ...
2
votes
1answer
196 views

Why does nobody use indentation in css? [closed]

I find css quite hard to read sometimes. Indents, depending on the dom structure, would greatly increase readability. Consider the following example: #page { text-align:center; ...
8
votes
1answer
383 views

Is deep nesting of control flow in code a studied problem?

I made the case to coworkers that deep levels of control flow was harmful to the readability of code. Example, taken from the relevant stack overflow question If you need more than 3 levels of ...
0
votes
1answer
84 views

Design patterns for ERP software with clients and web service

I'll will make ERP software for managing data for business activities. The solution must have two big parts: a WPF application for all the clients and an ASP MVC Web API application for all the ...
4
votes
2answers
154 views

Coding Patterns: Defensive copying

While watching a youtube video on Value Types in Swift, I was surprised by a simple example (around the 3:00 minute mark) that was given to demonstrate the pitfalls of reference types. Example code: ...
2
votes
2answers
441 views

Should we “balance” the amount of codes between headers and cpp?

As far as I know, cpp usually contains far more codes than headers, mainly because they contain implementation details of functions instead of just one line of function definition. Here comes to my ...
51
votes
6answers
4k 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 ...
170
votes
37answers
115k views

Should curly braces appear on their own line? [closed]

Should curly braces be on their own line or not? What do you think about it? if (you.hasAnswer()) { you.postAnswer(); } else { you.doSomething(); } or should it be if (you.hasAnswer()) { ...
116
votes
19answers
59k 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) ...
2
votes
2answers
139 views

Why did languages such as shell scripting and perl use $ in front of variable names?

Context Perhaps I'm just use to C-esque styled languages but having a sigil in front of a variable (e.g. $VAR) always strikes me as weird. Question Why do some languages such as Perl and shell ...
71
votes
14answers
29k views

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

In object-oriented programming, there is of course no exact rule on the maximum length of a method , but I still found these two quotes somewhat contradicting each other, so I would like to hear what ...
22
votes
9answers
15k views

Why are people so strongly opposed to #region tags in methods?

I hear a lot about keeping methods short and I've heard a lot of programmers say that using #region tags within a method is a sure sign that it is too long and should be refactored into multiple ...
-2
votes
1answer
88 views

Coding style - return object or set exposed properties

I have two coding styles: public class Age { public double AgeYear { get;} public double AgeInDays {get;} public Person GetAge() { int x; //implementation that calculates ...
4
votes
1answer
135 views

Is there a programming language which requires argument qualifiers (reference/value) to be specified at the call point?

For quite a long time now, I have been using a calling convention from C++ google style guide, which boils down to the following: "[for a function] arguments are values or const references while ...
13
votes
5answers
587 views

Is scientific code a different enough realm to ignore common coding standards?

Lately I've been trying to wrap my mind about the following fact. On one hand, there is a host of coding guidelines and standards for what is considered to be "healthy", "clean", "well-written" and ...
2
votes
7answers
2k views

What to use instead of IDs in selectors in CSS

I recently installed a csslint package for my Atom text editor. I keep getting warnings saying "Don't use IDs in selectors." I found this weird since I've always been using IDs in selectors in CSS, ...
4
votes
3answers
380 views

Are for loops allowed in the “Clean Code” set of rules?

Given the set of rules explained in "Clean Code", can one really use for loops? My confusion stems form the fact that a for loop is a low-level construct per se, thus it can only be used at the very ...
6
votes
6answers
388 views

How to follow the 80 character limit best practice while writing source code?

So as you know there is a best practice saying Limit a row of source code in 80 characters. Here are 2 links: Why is 80 characters the 'standard' limit for code width? Is the 80 ...