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

learn more… | top users | synonyms (2)

3
votes
1answer
85 views

Importing namespaces inside another namespace

I generally like to organize classes I make into modules by using namespaces, and I also don't go more than 2 namespaces deep but it's still painstakingly hard to fully qualify everything. I've ...
0
votes
0answers
49 views

Where do you put your profiling code?

I just developed an algorithm and additional to the usual unit tests I wrote a profiling "test" that I was using to measure and optimize its performance. It is structured similar to a test (arrange: ...
0
votes
2answers
81 views

Should I log errors in the function they occur? or pass them back and log them when control returns?

One of the things I love about Go is how they encourage passing errors as return values, but when it comes to logging what is the most maintainable solution: passing the error as far back down the ...
1
vote
1answer
59 views

Python file naming convention?

I've seen this part of PEP-8 https://www.python.org/dev/peps/pep-0008/#package-and-module-names I'm not clear on whether this refers to the file name of a module/class/package. If I had one example ...
4
votes
3answers
874 views

Is break a code smell?

I'm asking in terms of a loop, obviously break is important in switch statements. Whether or not switch statements themselves are code smells is a separate issue. So consider the following use cases ...
41
votes
8answers
4k views

When is it appropriate to make a separate function when there will only ever be a single call to said function? [duplicate]

We are designing coding standards, and are having disagreements as to if it is ever appropriate to break code out into separate functions within a class, when those functions will only ever be called ...
21
votes
7answers
2k views

Specify optional parameter names even though not required?

Consider the following method: public List<Guid> ReturnEmployeeIds(bool includeManagement = false) { } And the following call: var ids = ReturnEmployeeIds(true); For a developer new to ...
1
vote
2answers
166 views

How to deal with Classes having the same name (different packages)

My R&D team have Java packages containing classes with the same name. For instance: com.myapp.model Device ... com.myapp.data Device ... We had a discussion, the names conflict when both ...
1
vote
0answers
65 views

Function to return a string - Which is cleaner? [migrated]

I was having a discussion with my coworker about a function that returns either an empty string, or a string of a css class. The function is passed an object which has an HTTP status code, and then ...
4
votes
3answers
228 views

I want to overload a function with the same type parameter; what should I do?

I'm creating an API, and I want to overload a function for strip: QString MyClass::strip(); QString MyClass::strip(QRegularExpression open); QString MyClass::strip(QRegularExpression close); QString ...
3
votes
2answers
293 views

Is it good practice to have your C++/Qt functions always check all its arguments for null values?

Backstory While developing with Qt Signal/Slots, I came across a few segmentation faults that had me puzzled as to what was causing it. Eventually I figured out that you could actually pass a slot ...
1
vote
1answer
130 views

Javascript Closure Style Similar to Java Class Structure

PROBLEM: There is a coding imperative (S. McConnel, Code Complete) that one shouldn't code on language, but by means of it, e.g. doing right style things even if language doesn't have some ...
6
votes
4answers
176 views

What is the best way to split up large methods where each subtask depends on previous tasks?

According to this question and just about every style guide I've ever read, large methods are bad. However, suppose I have a method that does the following: Receive a JSON String from some service ...
5
votes
3answers
299 views

Is it ok to have multiple classes in the same file in Python?

I'm freshly coming to the Python world after years of Java and PHP. While the language itself is pretty much straightforward, I'm struggling with some 'minor' issues that I can't wrap my head around — ...
0
votes
1answer
55 views

How confusing is `new SomeCollection(values…)::contains` as a Predicate? [closed]

Traditionally, a function that want to skip certain items during processing will accept a Collection or var-args argument, but in the Java 8 world I think I should switch to Predicates. Now, since ...
2
votes
2answers
112 views

python - differences between reusable code vs. code for solving specific tasks

Reusable code (ex. libraries and frameworks) and code written to solve a specific task and not meant to be reused as a general tool (for example, code being used only by my 6 person team in a private ...
20
votes
8answers
3k views

At what point is it taboo to have loops within loops?

Just curious. The most I have ever had was a for loop within a for loop, because after reading this from Linus Torvalds: Tabs are 8 characters, and thus indentations are also 8 characters. There ...
5
votes
1answer
74 views

Why would you document a return type using scaladoc?

The following is snippet of an example from page 240 of the book Programming Scala (Wampler & Payne, 2009; O'Reilly Media): /** @return Parser[Money] */ def deductItem = deductKind ~> ...
6
votes
1answer
105 views

Is there a standardized practice for ordering attributes in HTML tags?

Thanks for looking. I am working on an AngularJS project and the attributes are numerous in many of my HTML elements: <button type="submit" ng-click="Page.UI.DetailView.ExecuteFunction()" ...
2
votes
2answers
123 views

Angular JS style guide when declaring variables

I'm new to Angular JS and working on a project with "legacy" Angular JS code. The code is about a year or half a year old. I often see stuff like this: var _link; _link = "http://localhost"; Or: ...
1
vote
1answer
115 views

Sorting Array before looping : best practice

I was going through JBAKE code at https://github.com/jbake-org/jbake/blob/master/src/main/java/org/jbake/app/Asset.java : 58 PFB the code. Why are we sorting the array here? if (assets != ...
1
vote
1answer
63 views

flatMap with if else vs combine with filter

When using reactive frameworks I have seen both solutions below to make a mutually exclusive selection of which stream will be forwarded (rxjava in this case) Observable.merge( ...
-3
votes
2answers
143 views

Why ever use exception throw (in C#) except for Class Library development? [duplicate]

Why would I ever throw exceptions in code? (except for one specific scenario where I am developing a class library which the consumers of it, will not want / be able to change). To be more specific, ...
42
votes
6answers
9k views

Is it better to check `c >= '0'` or `c >= 48`?

After a discussion with some my colleagues, I've a 'philosophical' question about how treat the char data type in Java, following the best practices. Suppose a simple scenario (obviously this is only ...
1
vote
1answer
78 views

Possible design patterns for a service that synchronizes two third party services [closed]

I am currently in the process of refactoring a web service that synchronizes two third party services. The two services do not really interact well with each other, and there is quite a bit of ...
0
votes
2answers
102 views

What are good ways to measure project size? How do I compare the size of my project to other projects? [closed]

Background I am currently working for a quite large (relative to what I have done before) hobby project. I would like to compare the size of this project to other open-sourced projects but I cannot ...
2
votes
1answer
123 views

implementing an extended interface on a concrete class

I don't know if this is a best practices or not. If I have a interface that extends another interface such as : public interface A extends B{ public void something(); }; and a concrete class ...
2
votes
2answers
152 views

Passing fields (instance variables) by arguments (parameters) inside an object - does it make sense? [duplicate]

I believe this is language agnostic question - if it's not then please correct me. Let's say I have a class (code snippet is a kind of 'pseudo code') class Car: private steering_wheel private ...
0
votes
2answers
67 views

Why don't style-guides include longer explanations why something should be done in a particular way? [closed]

When I read coding style guides, such as the AirBnB Javascript Style Guide I just realized that these often do not provide deeper explanations why something should be done in a particular way. At ...
5
votes
4answers
169 views

Ruby: if variable vs if variable.nil?

I'm new to Ruby and I was surprised when I found out that all objects are true apart from nil and false. Even 0 is true. A nice thing about that property of the language is that you can write: if ...
2
votes
1answer
378 views

Why do Android programmers use Hungarian notation? [duplicate]

I see Hungarian notation in almost all Android code I see. It is used in the source code, in the samples, in code from other programmers I get to see, in code that presenters show at Android ...
0
votes
0answers
36 views

How to extend code which is without documentation and very difficult to decipher? [duplicate]

I'm a junior developer and I'm coming across code which was written in a way which can only be extended with very hacky code, time constraints don't allow me to spend weeks trying to decipher the ...
0
votes
3answers
145 views

Eliminating the bad cases in if to get a nicer code

I have read this link Should I return from a function early or use an if statement? and it triggered a conflict in my head. I agree that it looks nicer and cleaner and I guess that would be the way I ...
8
votes
4answers
666 views

Is this code structure beneficial in any way?

I was recently thrown into a Java web application project, and I’ve come across a number of classes that follow this type of format: public class MyThingy { private final int p1; private final ...
0
votes
0answers
46 views

Is marking members as static against object-orientated programming? [duplicate]

Me and my co-workers are having a bit of a discussion about one of the code analysis issues thrown by visual studio: CA1822 Mark members as static The 'this' parameter (or 'Me' in Visual Basic) of ...
-1
votes
1answer
110 views

Drawing the Line between Coding Style and Algorithm [closed]

Formatting with Indentations, White spaces, and New Lines obviously fit into the coding style category. if (a == b) { foo(); } // vs if (a == b) { foo(); } On the other hand, something ...
0
votes
4answers
231 views

Where to put try-catch statements [closed]

I have the following code statement that calls a separate class. if (newOrEdit.Equals("New")) { try { BusinessLayer.InsertOperator(operatorDetails); } catch (Exception) { ...
53
votes
6answers
3k views

Illusory code duplication

The usual instinct is to remove any code duplication that you see in the code. However, I found myself in a situation where the duplication is illusory. To describe the situation in more details: I ...
2
votes
3answers
208 views

What is the most readable way of passing arguments to the function? [closed]

I'm using JavaScript but the question can be generalized to all the languages. In a nutshell - I'm checking if a browser connecting to my site is a microwave and cater for that accordingly. What ...
1
vote
1answer
63 views

Exception to the 'Nested types should not be visible' rule?

Is the following an acceptable breach of the 'Nested types should not be visible' (Microsoft .NET code analysis CA1034) rule? I have a have a class, let's call it 'TandAOLL', this is tree and an ...
0
votes
2answers
62 views

What's the use of lint warnings vs errors? [closed]

I'm hoping someone who's given this some thought can help me understand. Most style-checking tools seem to distinguish between warnings and errors. To me, the point of a lint error is that a style ...
3
votes
3answers
254 views

non-optional pointers vs. non-const references in C++

In Other C++ Features, Reference Arguments of the Google C++ Style Guide, I read that non-const references must not be used. All parameters passed by reference must be labeled const. It is clear ...
2
votes
1answer
128 views

Type checking as opposed to multiple functions?

In statically-typed languages such as Java, code such as the following is common (not much of a realistic example, I know): public String flip(String text) { String result = ""; for (int i = ...
4
votes
2answers
123 views

Rebol refinements vs. dialects vs. objects

I occasionally get conflicted when using a language that isn't Rebol (happens from time to time) and get to thinking, hm—would life be easier in Rebol if this thing worked this way? To illustrate my ...
3
votes
4answers
153 views

Elegant way to handle multiple pathways based on compound condition [closed]

Consider the following: if (x == 5 || x == 10 || x == 12) { if (x == 5) { doSomething() } else if (x == 10) { doSomethingElse() } else { doSomeOtherThing() } ...
57
votes
4answers
7k views

Is it better to call a function that doesn't have an effect at that point, IF it improves code clarity?

I have three views in my program (iOS app). Only one of them is ever active at the same time so I set the visibility off for two of them and switch visibility as the user presses buttons. The views ...
1
vote
1answer
149 views

Lines of code that take on too much responsibility [closed]

Intuitively, I know that (in terms of a maintainable, understandable codebase) the following code is bad practice var foo = fooFunc(barFunc(),wooFunc(chewFunc())); and might be better stated as ...
1
vote
3answers
396 views

How to design a class for a fixed-length id?

I'm building an app in C# that needs a fixed-length id, which is a string representation of a hex number. E.g. "0fa5" is an example of such an id of length 4. The length would not need to change ...
29
votes
1answer
953 views

What is the term for an anonymous JavaScript function that's called immediately?

I'm writing a JavaScript style-guide for my team, so that we can organise and contribute our documents easier. But I've hit a small bump which is where my question applies... What am I supposed to ...
0
votes
1answer
62 views

In *nix, is there a practice for storing static libraries?

Lets say you are building an application that staticly links against libraries that you provide it. Where should you store these static libraries? Should you make a directory in the parent directory ...