Questions tagged [coding-standards]

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.

Filter by
Sorted by
Tagged with
1
vote
2answers
159 views

Introduce code standard into old code

Our main product is written in C++ MFC and follows the same code standard as MFC. Now we will start to develop new components, and think about whether we should continue to use the same outdated ...
1
vote
3answers
293 views

How to deal with long URLs in comments that exceed the 80 characters limit?

I generally try to adhere to the 80 character limit for each line of code to satisfy my colleagues, to satisfy the linting tools, and to maintain an image of professionalism when random people look at ...
4
votes
7answers
1k views

How do you know where you stopped in your codes after a 2-week break? [closed]

I just had a more than 2-week long vacation/business trip and I couldn't remember actually what was I working in my coding and where I stopped. Could someone recommend a best practice to solve this?
0
votes
1answer
537 views

Why did JUnit declare setUp and tearDown in camelcase, even though each of them is a single word?

Reference: http://junit.sourceforge.net/junit3.8.1/javadoc/junit/framework/TestCase.html#setUp() setUp should have ideally be named as setup I've explored if any duplicate method setup is used in ...
1
vote
2answers
79 views

Is there a guideline on writing message that are shown to users of an app?

Is there any guideline on writing message which are shown to the user of an app using toast? For example, if an error occurred, should the app display Failed writing to the file or Failed ...
1
vote
1answer
51 views

HashMap versus Object ? Which one is better to finally generate JSON output with KEY and VALUE

I do have this use case. callers(APIs in same microservice or different microservices) wants to report different KEYS and VALUES as an audit as part of their methods. There is a high possibilities ...
1
vote
2answers
99 views

Python method docstring: to use or not to use Args: Returns:

Default docstring from PyCharm automatically creates template with Args: and Returns: sections. However I have observed that this prompts people to say obvious things, frequently just stating the ...
0
votes
1answer
46 views

Name for a library that provides an API for other libraries

I've been working on a library at work which provides a simplified API for a few underlying libraries (face recognition, text to speech, etc.). My boss asked me the best way to describe this concept ...
-4
votes
1answer
147 views

File structure of object-oriented projects seems cluttered [closed]

In computer science courses at University, assignments written in OO languages such as Java had file systems similar to this: TreeNode.java BinaryTree.java Assignment1.java etc. ... In writing some ...
2
votes
1answer
129 views

Should I use complex expressions as function arguments?

I recently started working as a programmer and I am currently going through some codes (in C#) written by my colleagues. I have noticed that they tend to include logic within function calls within ...
-1
votes
2answers
177 views

What to name a class that acts as a container for a collection but isn't a collection itself? [closed]

I have an object that acts as nothing more complicated than a data store for a collection of items. I do this because it lets me bind the data to a single object, which I can store in the Unity (game ...
1
vote
1answer
164 views

Should “Impl” naming always be avoided?

When implementing interfaces, as a general rule, Impl is evil. Ok, but is it evil in the following case? I've a service that has (and probably will have) only one implementation. In such case, ...
-4
votes
1answer
75 views

Public var vs protected var and get function [closed]

I've noticed this style of code a lot in frameworks like Symfony and Magento 2 (which is based on Symfony): <?php class Foo { protected $foo; # construct function - not ...
2
votes
1answer
196 views

Is there a term for functions starting with the “Is” prefix?

There are a number of functions of a kind; returning a boolean, and the name always starts with the "Is" prefix. e.g. IsAlive(), IsDead(), IsKeyPressed(), IsKeyReleased(), etc. How do we categorize ...
-1
votes
1answer
57 views

Storing average value in database or global scope?

I have a ratings web app where I want to output the average of all the ratings. How I'm currently doing it is recalculating the average every time a new review is posted and storing that in a database ...
8
votes
2answers
372 views

Is it a good practice to create new variable to see the output of a function?

Consider these 2 types of implementation: public int add(int x, int y) { return mysteriousAdd(x, y); } public int add(int x, int y) { int output = mysteriousAdd(x, y); return output; } ...
2
votes
1answer
222 views

Naming Convention [closed]

When we determine names for the variables, there are two important issues that the people mention: The variable names must be explanatory. For the sake of this, their names can be long.` The variable ...
34
votes
4answers
6k views

Is it enough for methods to be distinguished just by argument name (not type)?

Is it enough for methods to be distinguished just by argument name (not type) or is it better to name it more explicitly? For example T Find<T>(int id) vs T FindById<T>(int id). Is there ...
1
vote
2answers
185 views

Unit testing similar wrappers - or single unit test is enough?

I'm working on a service which has a lots of dependencies. The way how I call them is I'm wrapping each service client around an Adapter. Like this (I'm using Java): public abstract class AdapterBase&...
91
votes
14answers
7k views

How can I avoid always feeling like if I completely rebuilt my program from scratch I'd do it much better? [closed]

I have learned a significant amount of coding, however, it's always been in a scientific environment (not computer science), completely self-taught without anyone to guide me in the right direction. ...
1
vote
2answers
118 views

When using an ORM when should I sacrifice performance for convenience?

I work with SQL Alchemy a lot and, as a "lazy programmer", I enjoy the convenience it offers. But the "diligent programmer" in me often worries about optimisation and the performance of the queries ...
3
votes
2answers
149 views

What Software Delivery Guidelines are appropriate when outsourcing?

I started working at a very small company that regularly (not too often) has to outsource some software developments. The external suppliers than have to deliver something. As I now have seen is that ...
0
votes
2answers
81 views

Is it a good idea to let database surrogate key values spill out into other aspects of code (HTML, Controllers, Model, Repository layer)?

Is it acceptable to use id in HTML forms and subsequent code processing (controller, view, model, repository layers)? For example I need to show something like this on a web page: Select Motor ...
3
votes
2answers
82 views

HTTP Methods - what about only using POST for Ajax calls?

You can find whole articles theorizing when you should use what METHOD in what edge case. It mostly comes down to this; every action needs to be simplified to in just four flavours (GET, POST, PUT, ...
2
votes
4answers
398 views

What is the optimal way to perform 5000 unique string replace functions in terms of performance?

Restructuring some code, and the way I built it up over time has portions that look something like this: s.replace("ABW"," Aruba "); s.replace("AFG"," Afghanistan "); s.replace("AGO"," Angola "); s....
-1
votes
2answers
195 views

SQL Coding Naming convention: Variable same name as Columns

Is there a coding naming convention principal for SQL variables? Can variables be named the same as column names, I heard in different companies, this may cause confusion. However in C# below, its a ...
3
votes
2answers
427 views

How to name a Boolean variable that represents either of two options?

I'm developing an application with Python. I want to have a Boolean variable that represent whether something is buy or sell but I'm not sure how I should name it. Here are my current ideas: isBuy ...
2
votes
3answers
564 views

How do you denote a variable in a comment?

Let's say I have the following function in Python: def foo(one, two): return one + two And I want to document it with "adds one to two". However, this is confusing, because I could just mean ...
3
votes
1answer
417 views

Method naming: to vs as vs get

Do the words to, as and get have any special meaning when used in method names? Examples to new Integer(4).toString() get Integer.getInteger("system.unknown.property",4) as Arrays.asList(...
0
votes
4answers
203 views

Magic __init__ and regular init methods in a python class

Is naming a regular method init only confusing or is it an error? class A: def __init__(self, x): self.x = x def init(self, y): self.y = y**2 def reset(self): ...
43
votes
7answers
6k views

Is using parameter names that differ from type names only by casing considered a bad practice in C#?

I see questions similar to this with regards to parameter names that match properties on the class, but I can't find anything regarding using a parameter name that is the same as the parameter type ...
2
votes
3answers
194 views

Defining a lot of attributes in a class

Suppose that you have to develop a program which stores the products with their features and perform some operations on them, and you decide to design a class to represent the products. Each product ...
2
votes
4answers
579 views

Avoiding if statements in Nested FOR loops

Please pardon me if this is a duplicate question. I have two nested for loops which will iteration for around mn times (the complexity is around 3k). Inside these for loops, I have 3 If conditions ...
0
votes
1answer
110 views

Is raising an unrelated exception for convenience acceptable? [duplicate]

Let's say I have a function that returns a dataset. First it tries to read it and if that fails it is requested from an API and then written: def get_dataset(): try: df = pd.read_csv('...
-3
votes
4answers
158 views

Should each method have its own object created everytime

I have a bit of confusion whether a method should create an instance of a class each time it's invoked? It is all possible to move this instance creation part to the constructor and just use the ...
5
votes
2answers
278 views

Is it wrong to use any type of parameter to determine behavior?

According to Is it wrong to use a boolean parameter to determine behavior?, I should not use a boolean parameter to switch behavior inside a function. How about other types of parameters? For example,...
4
votes
5answers
2k views

Positional arguments vs options in a command-line interface

Consider the following command-line program manage-id. It does these things: manage-id list (list all usernames and user-ids) manage-id show <username> (shows ...
3
votes
1answer
93 views

What security practices do I employ when building a library that requires low level root access to certain devices and files?

Backstory I am writing a library that accesses the kernel module, uinput which allows you to create or take control of devices in /dev/input/event#, and insert events into them. A simple usecase ...
0
votes
1answer
647 views

Is it okay to use var on purpose in ES6, as opposed to let?

I was really glad that ES6 introduced the let keyword for defining variables. var scoping rules can lead to all kinds of issues, especially when working with loops and event handlers. Even when ...
7
votes
6answers
922 views

How to name a method which may or may not perform an action depending on a condition?

I stumble across this case somewhat often, and I'm surprised about finding so few similar discussions around the web. This question is very related, but my problem is that I want a method that does ...
3
votes
2answers
92 views

Should one create shareable private class member or keep variable in method scope to pass it as a second method argument?

Recently I had to refactor some legacy code. As in most cases, I had to split big parts of code into smaller, cleaner and readable functions. I ended with many functions, that had multiple, weird ...
4
votes
4answers
1k views

What is a good naming convention for date properties? [closed]

What is a good naming convention for date variables or properties in an Object-based, strongly typed language like C# (and by extension, for date database columns)? Do you use the word "date"? I'm ...
-7
votes
1answer
183 views

Where should I store data related to UI/presentation?

Say, I have a table Categories. On a page I have a header and for each category the colour of a header varies. A colour is of the presentation level and I've heard that what's related to the UI/...
3
votes
1answer
245 views

What motivates syntactic preference regarding pointer declaration in C/C++? [duplicate]

Both of the following are valid pointer declarations in C/C++: int *x; int* x; The former seems to be preferred by seasoned C/C++ programmers. I personally find the latter to be easier to understand ...
2
votes
1answer
396 views

Not prohibited, but disallowed — which http error code should I return?

I know that if user is forbidden in an admin's area, I should return 401 or 403 status error code. However, what I want to prohibit an admin for accessing a user's dashboard also? An admin has its own ...
-3
votes
2answers
384 views

Writing readable code and not overdoing it with naming [closed]

I've been in an argument at work about writing readable code. It was mainly about variable and method names and the idea that comments are worthless if the code is readable enough. I would not like to ...
-3
votes
1answer
198 views

Why PHP does not have a common coding convention [closed]

Why there is common coding convention in PHP. Just like python has pep8 .Some frameworks prefers camelcase but wordpress uses underscore while naming functions and variables which is actually ...
5
votes
6answers
708 views

How to eliminate a if-else block which is used to determine behaviour according to a boolean input?

According to Is it wrong to use a boolean parameter to determine behavior?, I know it is bad: public void myFunction(boolean b){ if(b){ }else{ } } and it should have separate function: ...
2
votes
4answers
623 views

Naming similar variables [closed]

I need few related variables (for example I have the lengths of 3 lines given. I have to say whether they form a triangle). Which variable naming convention is preferable in Java? len0, len1, len2 ...
12
votes
2answers
1k views

Is it bad practice to create blocks of code?

In C++, is it bad practice create blocks of code inside some function, such as the following: bool f() { { double test = 0; test = // some other variable outside ...