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

learn more… | top users | synonyms (2)

0
votes
2answers
73 views

Comment on interface class and implemented class both? or interface class only?

Now I'm commenting on both on interface class and implemented class. But sometimes, I feel it's unnecessary commenting both. So I want to hear from Pros which is a better way? commenting on both? or ...
90
votes
11answers
18k views

Should I follow a bad coding style just to follow the established conventions at my workplace?

I've been working at my job for about a year. I primarily do work in our GUI interface which uses methods from a C backend, but I generally don't have to deal with them except for return values. Our ...
-2
votes
0answers
74 views

If an argument is assigned with a condition, which part would you put the if statement at? [closed]

It's very common that there are some conditions applied to variable assignment. For example (in python): #input validation, assume the function in the future will assert an error if thisisRight(): ...
1
vote
1answer
54 views

Implicit/Explicit Assertions

During code review, a minor suggestion was presented that some implicit behavior be made explicit. The reviewer had skimmed over the code in question, became confused after mistakenly interpreting the ...
1
vote
1answer
74 views

Is nesting component properties maintainable in the long run?

I'm building components in Vue.js. They look like this: <template> <form :schema="form.schema" :options="form.options"></form> </template> <script> export default { ...
11
votes
6answers
546 views

Naming: Should you sacrifice briefness for clarity?

For example, the following function loops through an array which contains the name and errors of an input field. It does this by checking the name of the validating field and then pushing the error ...
5
votes
3answers
221 views

Functions that contain single statement?

Is it OK to have functions that have single statements? I usually make functions that have single statements. I believe these increases code readability and i am able to write code faster as they ...
0
votes
2answers
277 views

Why does nearly everyone use .h-files instead of .hpp-files in C++-Projects nowadays? [closed]

I just wondered why most people use the .h extension in their C++ Projects, even though the standard is actually .hpp? Isn't this a little stupid? I always thought precision in differencing between ...
13
votes
5answers
840 views

OOP Coding style: initialize everything on constructor?

I still consider myself as an apprentice programmer, so I'm always looking to learn a "better" way for typical programming. Today, my coworker has argued that my coding style does some unnecessary ...
10
votes
5answers
639 views

Is placing text markers inside of strings bad style? Is there an alternative?

I work with massive strings which need a lot of manipulation. For example, I might generate a string like this: Part 1 Boat Section A Programming Part 2 Partitioning boats for ...
1
vote
4answers
159 views

Variable name which sometimes refers to an object and sometimes to a string

Sorry for the confusing title - this is best illustrated by an example (hypothetical but hopefully illustrative). For 99% of my application a Zip Code is considered as a string, so I consistently use ...
0
votes
1answer
23 views

Convention where to place unexportable functions

For the example's sake let's say there is a given file math.js. Think of it as a module containing many reusable functions. The content of file is: export function area(shape) { normalize(shape) ...
12
votes
1answer
231 views

Introducing additional local variables as comment replacement

Is it good style to use additional, technically superfluous, local variables to describe what's happening? For example: bool easyUnderstandableIsTrue = (/* rather cryptic boolean expessions */); if(...
15
votes
6answers
419 views

How can I promote and encourage high quality code?

I work as an iOS developer in a small outsourcing company in a team of 4 people. We work on a project that started a couple of years before I and two other developers joined the company. Before that ...
2
votes
1answer
83 views

Is avoiding having the fields representing the same object in different communicating classes reasonable?

I'm developing a program which does communication to different types of devices (with respective protocols). It should concurrently acquire messages from devices and write them to a file with specific ...
2
votes
2answers
142 views

Can conditional break in a loop be rewritten for easier understanding?

while cond1 ... if cond2 ... else ... break The while loop above has two termination conditions, cond2 and !cond1 !cond2 When the commands that are represented ...
6
votes
2answers
204 views

In Java 8, is it stylistically better to use method reference expressions or methods returning an implementation of the functional interface?

Java 8 added the concept of functional interfaces, as well as numerous new methods that are designed to take functional interfaces. Instances of these interfaces can be succinctly created using ...
4
votes
4answers
393 views

Should I be using const more in C++?

There are some things I am pretty strict about, but const has not been one of them. For example, I might make a local variable that I use three times in a function, that does not get changed, and yet ...
30
votes
8answers
4k views

Are assignments in the condition part of conditionals a bad practice?

Let's assume I want to write a function that concatenates two strings in C. The way I would write it is: void concat(char s[], char t[]){ int i = 0; int j = 0; while (s[i] != '\0'){ ...
3
votes
0answers
66 views

When should bool.boolValue be used?

Recently a co-worker has taken to checking boolean values in the following manner: if boolVar.boolValue { ... } These variable are generally declared explicitly as boolean types either using: ...
1
vote
5answers
197 views

Where to declare a variable and define a function in Javascript?

I'm reading the book JavaScript: The Good Parts. On page 113 it recommends function expressions instead of function statements, because statements are subject to hoisting: The statement: function ...
95
votes
10answers
15k views

What kind of bugs do “goto” statements lead to? Are there any historically significant examples?

I understand that save for breaking out of loops nested in loops; the goto statement is evaded and reviled as a bug prone style of programming, to never be used. Alt Text: "Neal Stephenson thinks it'...
0
votes
0answers
36 views

Qt Naming Schemes for returns of boolean member variables: enabled(); vs isEnabled(); ?

In building my classes, I have noticed that I have not been very consistent about naming my boolean returns. In Qt; I notice that many of their classes use the is prefix, but checking their coding ...
4
votes
1answer
194 views

Are there any scenarios where a JS function expressions would need to refer to its “name”?

Anonymous function expressions in JS bug me as they make stack traces and Chrome Dev Tools profiler output harder to use, so I've decided to name ALL my function expressions from here on in. The ...
3
votes
1answer
331 views

Why are pure functions easier to reason about?

In computer programming (I code in c#), why are pure functions easier to reason about? From my own experience, I find that pure functions are easier to reason about because they lack side effects, ...
4
votes
2answers
284 views

Practice for returning a value or equivalent variable?

I think it would be easiest to explain what I'm asking with an example. function getLastNode() { let current = this.head; if (current == null) { // Here, we could either return ...
5
votes
4answers
451 views

In C/C++, should I use 'const' in parameters and local variables when possible?

This question is inspired by a question about final in java. In C/C++, should I use const whenever possible? I know there is already a related question about using const in parameters. ...
4
votes
3answers
234 views

Naming convention for functions which have side effects? [closed]

I heard somebody say their language has a convention where the names of functions which mutate state must end with an exclamation point. I'm trying to write more functional code and I like the idea of ...
2
votes
2answers
262 views

Using common language features only among my working environment, is it a good habit?

Now I'm working in a mobile apps company, and Objective-c ,c++ (for iOS) and Java (for android) are my most frequently used language. Is it a good habit to just use common language features among them?...
0
votes
2answers
120 views

SonarQube is complaining about: “Use isEmpty() to check whether the collection is empty or not.”

So as my the title says, SonarQube is complaining whenever you use list.size() == 0 or list.size > 0 However I started changing to isEmpty() and !is.Empty() and noticed the code becomes way ...
1
vote
3answers
138 views

Equivalent to “Principle of Least Astonishment” for code style?

The Principle of Least Astonishment is a design guideline that you should make your behavior match what people would expect. Don't redefine equality, behave consistently, choose sane defaults, etc. ...
2
votes
4answers
179 views

If a function contains only a switch, is it bad practise to replace the break; statements with return; statements?

Lets say I have a function that takes an argument, does some action based on the value of that argument and returns false if there is no action for that value. (pseudo-code): bool executeSomeAction(...
1
vote
1answer
118 views

C Programming Guide Question: How to track error codes?

I have a project in visual studio that contain more than 10 header and source files. I start to realize I did not assign return error codes for each header correctly (i.e I found out that there are ...
21
votes
6answers
7k views

Is readability a valid reason to not use const in (reference) parameters?

When writing some functions, I found a const keyword in parameters like this: void MyClass::myFunction(const MyObject& obj,const string& s1,const string& s2,const string& s3){ } ...
3
votes
3answers
327 views

When declaring an array in Java, what is the conventional location for the square brackets?

I've seen two methods of declaring an array, such as the String[] args portion of the main method: public static void main(String args[]){ or public static void main(String[] args){ The textbook ...
5
votes
3answers
200 views

Why use Either over (checked) Exception?

Not too long ago I started using Scala instead of Java. Part of the "conversion" process between the languages for me was learning to use Eithers instead of (checked) Exceptions. I've been coding this ...
1
vote
3answers
344 views

Combining logical statements onto 1 line in C#?

A simple question as to whether or not this would be a proper way to combine logical statements for readability and organization purposes. The 'standard' way I was taught to write code: ...
2
votes
4answers
218 views

Approach for refactoring a function that has lots of special braching

I am writing a function that operates slightly different depending on the data passed in. The common and unique code is mingled. I don't like what I have and am looking for a better way. Hopefully, ...
7
votes
2answers
199 views

Is it wise to use Clang for personal code analysis in a project that builds with gcc?

I started to work on several C projects that are building using gcc. I believe this choice was made for several reasons: Had to cross-compile for arm very early on (I think). Performance is the first ...
0
votes
0answers
88 views

How to clarify the control flow when dealing with many callbacks?

Traditional programming could be done quite readable. Like this: FUNCTION do_HTTP_request(url) { if(!ask_user_if_he_wants_to_connect()) return; if(!network_is_enabled()){ ...
4
votes
2answers
218 views

Is it important to have a consistent commit message style on a team?

On my team of 5 coders, we've traditionally adhered to a common git commit message standard stating (only) two rules: commit messages should include the why rather than just the what and they should ...
3
votes
5answers
270 views

C++ auto-indentation (auto-style) in a multi IDE team

Is there a convenient and sustainable way to handle code indentation and style in a team in which multiple IDE's (Emacs, XCode, VS) are used by different programmers? We are using git, so, should we ...
1
vote
1answer
253 views

Windows batch files (.bat) coding style standard

Is there any standard/encouraged Windows batch file coding style? I would think that if I want my batch files to be easy to read/mantain, I should care about this, but searching the web I found very ...
2
votes
2answers
116 views

Using single-character variable names for function parameters? [duplicate]

Can using single-character variable names as parameters in a function okay? For example, look at the code below: public static int factorial (int x) { if (x == 0) { return 1; } ...
-2
votes
4answers
78 views

Multiline formatting of long function signatures/calls [closed]

Let's say you have a signature like so: public void MyFooBar(IExtraSuperLongTypeName param1, TypeA param2 ISomeotherReallyLongTypeName param3, TypeB param4, TypeC param5) Formatting in on one line ...
0
votes
0answers
36 views

Functions inside conditionals [duplicate]

Is it a poor idea for readability or maintainability to use functions in conditionals as in the following example? if (move_uploaded_file($file['tmp_name'], $destinationFile)) { // Do work } ...
4
votes
1answer
85 views

Is it good form to use an alphanumeric unique ID?

There is a company that I am pulling data from which has a unique ID for each record. However, the ID is alphanumeric (even contains a special character too). When I asked about this I was told that ...
1
vote
2answers
228 views

In Qt or C++, how should I check whether my `int` variable has been defined?

Short Problem: How should I check if integers are undefined, just as I can check QStrings for having NULL values? Backstory: This is my coding style when I am trying to avoid overloading my ...
0
votes
4answers
281 views

How deal with negative feedback on code style from senior developer? [closed]

Background I have been programming mainly in Python in the past years and mostly on my own projects. I have developed some of my own small stilistic conventions like leaving 4 numbers of empty lines ...
3
votes
1answer
190 views

Is it considered a bad practice to oversize an array so that negative indices behave well?

I have been practicing implementing some classic dynamic programming algorithms and was wondering if my implementation of the longest common subsequence search has a significant code smell. In python,...