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

learn more… | top users | synonyms (2)

0
votes
1answer
118 views

Are all boolean arguments flag arguments, and thus a code smell?

Martin Fowler describes the Flag Argument code smell as a "kind of function argument that tells the function to carry out a different operation depending on its value". Answers to Is it wrong to use ...
0
votes
0answers
37 views

JavaScript coding and project organizing conventions

Recently, I've started working with JavaScript projects closely and with my C# background I am already wondering about some conventions. I see a lot of source files that use dots to separate words (i....
0
votes
1answer
103 views

What scientific support does some coding standards have?

Let's consider the rule in python PEP8, coding standard for the linux kernel etc saying that a line of code are not allowed to be longer than N characters. To this rule there is normally a few ...
5
votes
2answers
113 views

Create a new variable to shorten code

I have often wondered about the implications of shortening code by assigning temporary variables with shorter names to data accesses with long names. It's best illustrated by an example (in Ruby, but ...
0
votes
3answers
282 views

If of loops or loop with if

Assuming the compiler is smart enough to only evaluate the if in the second example once, which version should one (semantically) use and why? if (b) { for (auto a : as) { foo(a); } } else { ...
0
votes
6answers
457 views

Is it easier to read and maintain code using “!” characters, or implying “Not” in the method name?

I often find that "!" characters (meaning "not" in C-based languages) are easy to overlook. So I sometimes create methods that return the inverse result. For example, instead of doing this: if (!...
1
vote
1answer
52 views

When to have a generic method for multiple tasks when some differ?

I process a lot of tweets in real time using python and for each tweet I need to assign it in to a specific bucket. I have about 50 buckets, each with their own rules. The majority of them are simple ...
2
votes
4answers
241 views

Are some people just unable to code? [closed]

So for the past year or so, I've been trying to self-teach myself programming. The problem is, every time I start to try and teach myself (like on Codecademy and such) I start off great and then ...
2
votes
1answer
106 views

Why do we use architecture-specific types in C

I think that the type names in Rust are much better than the ones in C. I'd choose f64 over double and u32 over unsigned int or uint_32t any day. Is there any reason (other than tradition) to use ...
0
votes
1answer
98 views

`var is None` vs `var == None`

I often see var is None in python code, using is to test equality only works for a very few objects like None. I used to think that it's better practice to use == to compare equality even if is is ...
2
votes
3answers
240 views

Why do assertions in Java need to get enabled?

I really like the concept of assertions in Java in the way how to use them. It's much easier than to write an if and then throw an Exception/Error. But the thing I don't understand is, why do they ...
80
votes
9answers
7k views

Has / can anyone challenge Uncle Bob on his love of removing “useless braces”?

I hate referencing paywalled content, but this video shows exactly what I'm talking about. Precisely 12 minutes in Robert Martin looks at this: And says "One of my favorite things to do is getting ...
2
votes
1answer
148 views

What is “low code”?

Recently I have come across this article, which claims that "low-code" development is very important in the rapidly changing world of software engineering. I got the idea that "low-code" has something ...
5
votes
3answers
318 views

Is nesting try-catch statements still a code smell if nested within a loop?

I have heard that nesting try-catch statements can often be a code smell, so I'm wondering whether this situation is an exception. If not, what would be some good ways to refactor? My code looks like ...
1
vote
1answer
43 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 user-...
0
votes
2answers
66 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 ...
3
votes
1answer
44 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 ...
1
vote
1answer
105 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
46 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
95 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
117 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 ...
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 ...
-2
votes
2answers
121 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
137 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 ...
-4
votes
2answers
112 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
2answers
101 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 _.findPrevText(node....
3
votes
2answers
172 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 ...
4
votes
1answer
67 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 ...
5
votes
2answers
153 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
1answer
103 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.
9
votes
3answers
283 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 ...
3
votes
4answers
235 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 ...
21
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 ...
1
vote
2answers
84 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
97 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 ...
6
votes
4answers
248 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
79 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; ...
14
votes
3answers
276 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 FooSaver(object)...
0
votes
2answers
83 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 ...
58
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
199 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; font-weight:...
4
votes
2answers
158 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: ...
0
votes
1answer
108 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 client....
2
votes
2answers
447 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 ...
2
votes
2answers
142 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 ...
-2
votes
1answer
89 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
146 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 ...
14
votes
5answers
609 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 ...
4
votes
3answers
396 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
406 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 ...