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

learn more… | top users | synonyms (2)

-3
votes
0answers
29 views

A JS linter/beautifier than enforces braces around single statement blocks? [on hold]

I recently started using jshint to lint our javascript code before it is committed. However I found that I could still do this: if (condition) statement; I'm trying to find a linter that will ...
0
votes
1answer
116 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
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
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
6answers
455 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 (!...
8
votes
7answers
1k views

Why would an employer ask for a 'long' code sample? [closed]

What would a large project that spanned multiple files and >1000 lines show to an employer that a few individual files and a couple hundred lines couldn't capture?
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 ...
9
votes
10answers
2k views

Single Line Statements & Good Practices

I have recently acquired a habit which I know many of you may frown upon, but which, in the end, helps me keeping an eye on global code structure rather than on the structure of a single, (sometimes) ...
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 ...
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 ...
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 ...
10
votes
3answers
2k views

using unsigned integers in c, c++

I have a very simple question that baffles me for a long time. I am dealing with networks and databases so a lot of data I am dealing with are 32-bit and 64-bit counters (unsigned), 32-bit and 64-bit ...
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 ...
2
votes
1answer
147 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-...
155
votes
19answers
48k 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) ...
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 ...
-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?
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 ...
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
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 ...
5
votes
2answers
150 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
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 ...
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 ...
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....
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 ...
113
votes
23answers
16k 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
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 ...
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 ...
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.
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 ...
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
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 ...
27
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 ...
28
votes
13answers
2k views

Handling my antiquated coworker

I'm a fairly young programmer, and I work at a medium sized company's IT department. I have a coworker, and he is a really good Visual Basic 6 programmer. And I mean really good. Honestly. He 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 ...
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)...
6
votes
4answers
247 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; ...
11
votes
2answers
477 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
81 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 ...