Coding standards, or coding conventions, are sets of rules or guidelines designed to govern the process of code production in a software project. They're usually based on industry best practices or generally accepted conventions. They include naming conventions, style, prohibited features, and more.
-1
votes
0answers
86 views
Underscores at the variable names' end [on hold]
What is the general convention about using single and double underscores after variable names' end in software projects?
e.g.
int var__;
int score_;
In my project, single underscore is used after ...
0
votes
0answers
55 views
Adding a prefix identifier to a function name in order to keep code better organized - Book reference
I usually write a name for a function, using strong a verb followed by an object, example report.printSummary() (Code convention from Book: Code Complete: A Practical Handbook of Software Construction)...
4
votes
3answers
130 views
Organization level Coding Standard
I have been asked to document coding standards for javascript at my organization level. Does maintaining coding standards at my organization level sound worth enough? kind of old timers? with the way, ...
4
votes
2answers
274 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 ...
4
votes
3answers
200 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 ...
1
vote
0answers
58 views
What is the preferred way to check if an optional has a value without using it?
Which of these is the ideal way to check if a value exists without caring exactly what its value is?
if let _ = flags[.showField] { showField() }
if flags[.showField] != nil { showField() }
In the ...
1
vote
1answer
37 views
naming conventions / coding standards for methods in a service
At work, we are having 'arguments' about naming styles / conventions. Imagine having a service called UserSettingsService. This has 2 methods, one to get the user settings and one to save. Would you ...
14
votes
10answers
2k views
Disagreement with project lead on coding standards [closed]
So I'm working on a new project along with my project lead for the past 1 year.
Initially we had our own sub-projects that resided in separate git repos, I had little interaction with his code, so ...
0
votes
1answer
78 views
RESTful API conventions
I have an API that generates a resource randomly when requested.
What path could I use that would follow REST conventions?
A - /generate/random.png
B - /generators/random
C - ?
Should I place all my ...
1
vote
3answers
337 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:
...
4
votes
2answers
208 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 ...
-4
votes
1answer
127 views
Global variable or parameter?
Is it correct that homeitem should be declared inside the OnLoad method and overgiven to all the render methods instead of just declaring it as a global variable and accessing it by all the render ...
1
vote
3answers
279 views
Is it a good idea to have a method that starts with get without being an accessor?
Let's say you implement an interface like:
public interface Example {
InputStream getThatContent();
}
In this case there is no property, and the implementation may also have side effects (it can ...
1
vote
2answers
303 views
Overuse of var in C# [duplicate]
With in the introduction of anonymous types in C# we got the var keyword.
Now people use var everywhere instead of the correct type. The reasons I've heard given for this are:
It makes refactoring ...
0
votes
2answers
70 views
How to name variables that clash with functions?
As an example, in Python I have a lowest_prime_factor function which does it exactly what it says it does. Then, in another function, I need to call this function and store it. In another language ...
0
votes
3answers
106 views
Version-postfixed class name for REST api
I'm working on a Spring-based REST api that has v1 and v2 variants:
/api/v1/dates
/api/v2/dates
Correspondingly, there are v1 and v2 packages in the code base:
com.company.api.v1
com.company.api.v2
...
4
votes
1answer
65 views
Is it appropriate to catch all exceptions at toplevel, so that I can log the exception (and possibly save some basic state to disc) before exiting?
Suppose I am writing a program in F# for end-users. If there is an unhandled exception, the program will crash.
Now suppose that I want application-specific data in the crash report. I can get this ...
1
vote
0answers
38 views
In Objective-C,what is the naming convention around protocols and their implementation classes?
Is there a naming convention for protocols and concrete implementations of them in Objective-C? Specifically regarding a protocol that's used as an abstract 'service' or 'manager' class declaration.
...
0
votes
2answers
93 views
Parallel vs Simple Assignment question
I'm quite new to Python and learning it on Lynda.com, which does not seem to have any way to ask questions about lesson content. In a video about while loops there is this code:
a, b = 0, 1
while b &...
-1
votes
1answer
117 views
Java properties - no more get/set in names?
I don't getFoo/setFoo naming convention, that is so spread that it become a standard. Instead, I am using more and more just: foo() and foo(value) for reading and setting value. I also see this trend ...
1
vote
0answers
30 views
What are the boundaries of the term 'Consistency' in the context of system's design?
In many books on code style or design of the software systems authors often stress out the importance of being consistent, yet they do not give a precise and clear definition for it.
Now I need that ...
0
votes
1answer
57 views
In scala is it acceptable to have id variables written as `_id` instead of the regular camel case notation?
In Scala is it acceptable to have id variables written as _id instead of the regular camel case notation?
In the code most variables respect the camel case notation. However for variables referring ...
2
votes
0answers
102 views
Now that not all method declarations in a Java Interface are public abstract, should the methods be declared with these modifiers?
Starting with Java 8, default methods were introduced into interfaces. Effectively, this means that not all methods in an interface are abstract.
Starting with Java 9 (maybe), private methods will be ...
3
votes
2answers
197 views
Does breaking rules in the (ANSI C) standard lead to or equate with buggy code?
To my understanding, standards are mainly for code portability between compilers, but I'm curious if some things in the standard that are only treated as warnings when not followed can cause software ...
0
votes
1answer
72 views
Should I always use prefix private methods with an underscore in Python?
Prefixing methods and members with an underscore indicates internal use. For simple classes, I sometimes find the easier reading and typing of self.foo outweighing the indent of self._foo. Especially ...
0
votes
2answers
96 views
What is good practice when dealing with data integrated in the source code?
I've been tasked with overhauling a fairly large web-system that requires much user input. In an attempt to instruct the users when making input, the original creators has made extensive use of ...
1
vote
1answer
66 views
Coding guidlines for Controller and Dao?
My Controller code:
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
ObjectReader objectReader = objectMapper.reader(...
0
votes
1answer
120 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 ...
0
votes
2answers
85 views
Using Super.someMethod for added clarity?
Is Super.someMethod() a good practice to add clarity to the code by explicitly stating that someMethod is not a method included in the current class but in the parent class?
For instance, would this ...
21
votes
11answers
3k views
Should coding best practices always be used [closed]
When coding software, should the architecture always be best practices or practical practices in regards to the application being built?
If I am building a two page web application that might live 5 ...
-3
votes
1answer
99 views
According to GNOME guidelines, should git messages end with a full stop, or not? [closed]
According to GNOME guidelines, how sentences should be written in Git messages?
Should sentence in git commit message start with upper-case letter and end with a full stop, or lower-case without a ...
5
votes
3answers
372 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 ...
5
votes
5answers
328 views
Do you generally send objects or their member variables into functions?
Which is generally accepted practice between these two cases:
function insertIntoDatabase(Account account, Otherthing thing) {
database.insertMethod(account.getId(), thing.getId(), thing....
138
votes
14answers
23k views
Why does Uncle Bob suggest that coding standards shouldn't be written down if you can avoid it?
While I was reading this question, the top voted answer quoted Uncle Bob on coding standards, but I was confused by this tip:
Don't write them down if you can avoid it. Rather, let the code be ...
4
votes
2answers
110 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 ...
2
votes
2answers
201 views
Correct way for storing data for runtime use in stand-alone applications?
I am working on a project that involves a "team builder" type application, if you will using C#.
For the sake of simplicity, let us say it involves the user creating a "Team." There are three teams ...
101
votes
4answers
10k views
Does a `long` ban make sense?
In today's cross-platform C++ (or C) world we have:
Data model | short | int | long | long long | pointers/size_t | Sample operating systems
...
LLP64/IL32P64 16 32 32 64 ...
2
votes
1answer
102 views
What is MISRA 8-0-1 rule on init-declarator-list and member-declarator-list about?
I am reading company's coding guidelines, and I encountered the MISRA 8-0-1 rule, which states:
An init-declarator-list or a member-declarator-list shall consist of a
single init-declarator or ...
3
votes
1answer
83 views
Term for the current iteration of a recursive function call
Is there a standard or widely accepted term for referring to a variable within the current call of a recursive function where the last value of the same variable is passed as an argument? I am trying ...
0
votes
2answers
90 views
What is the accepted practice for handling numeric conversions under OOP?
I am making a weather app that involves temperatures. You can change between Kelvin, Celsius, and Fahrenheit just for fun.
However, temperature figures get used all over the place in different ways. ...
15
votes
5answers
645 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
445 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 ...
1
vote
1answer
188 views
In C, are large 'pointer chains' bad for performance or code cleanliness?
The following for example:
i = readString(&packet->data.play_server.updatesign.line1, pbuf, ps);
It has a large amount of nested structs/unions. Is this generally frowned upon in code ...
1
vote
3answers
302 views
Is it considered good practice to always have methods return a value?
Sorry for the terrible title but hopefully these snippets will give you the gist.
Method 1:
class Person:
def __init__(self, name):
self.name = name
def set_name(self, new_name):
...
3
votes
3answers
193 views
Would dependency injecting into entites be considered against SRP?
I asking a question on Stackoverflow earlier and someone pointed me to a previous post of his, He states that injecting a dependency into an entity violates the Single Responsibility Principle.
To ...
0
votes
1answer
129 views
Is it worth it to follow code conventions of Netbeans? [closed]
I am always not able to follow Netbeans default coding conventions like the following
Function should be N lines only
Method Length is N Lines (M allowed)
Warning: Do not Access Superglobal $...
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 ...
1
vote
2answers
595 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
3answers
276 views
The best practice for passing formatted string to methods
Though it might be trivial for someone, I find it a little inconvenient when someone formats the string while passing it as a parameter to a method. For e.g.
AddMessage( string.Format("{0} (" + ...
1
vote
0answers
336 views
Can this be used to implement Post Redirect Get pattern?
I am trying to implement proper a Post Redirect Get on a PHP site (question is language agnostic in nature however). I thought about it, and realized that running this code on every request seems to ...