Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
2answers
111 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
89 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
65 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
71 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, ...
1
vote
4answers
277 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
151 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 ...
2
votes
1answer
312 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
196 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 ...
2
votes
1answer
209 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
147 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
155 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
2answers
366 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 ...
1
vote
0answers
32 views

Where do I store the record sources for a form's controls?

I'm working on a Windows application that is used for tracking document review and audit information for my company. The back end is a SQL server database and most of the user tasks are basic CRUD ...
0
votes
1answer
69 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
155 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
247 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
756 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
86 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
398 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
650 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 ...
0
votes
0answers
42 views

How to name variables in the operation queue?

How to name variables in the operation queue? 1 - Don't change the variable name: function example($array) { $array = array_unique($array); $array = array_reverse($array); $array = ...
3
votes
2answers
84 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 ...
0
votes
0answers
34 views

When should assetions and when should Exceptions be used [duplicate]

Assume I am writing a library for calculating the velocity, given two datetime objects and a distance: #!/usr/bin/env python def get_velocity(t0, t1, distance): """ Calculate the velocity. ...
3
votes
4answers
482 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 ...
-6
votes
1answer
162 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
233 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
333 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
343 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 ...
-4
votes
1answer
182 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
684 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
500 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 ...
0
votes
2answers
1k views

Why is it uncommon (is it?) to use _ (underscore) in JS private vars?

Coming to JavaScript from C# and C/C++ world, I'm used to decorating my private members with underscore. But a couple of JS devs I know have told me it's not common in JS world, and my code looks "...
3
votes
2answers
57 views

Ajax response — is there an agreement on the structure?

Say, I make an ajax request to a server from a page, something like "show more articles". Is there a common agreement on the format or rather structure in which a result should be returned? Something ...
6
votes
4answers
520 views

Previous php programmer used <? tags I use <?php, what to do? [closed]

I am given a project where the previous developer used <? and <?= whereas I am using <?php and <?php echo. My questions: - should I rewrite all files _ or just when i need to tweak the ...
2
votes
2answers
215 views

Giving multiple classes in a single library the same name

The project that raised this question is in C#, but it could apply to most languages that use namespaces. I've read many things on good naming practices: "Don't prefix your class names with their ...
3
votes
4answers
362 views

Why is it common for naming 2 axis dimensions as width and height instead of length and width?

Pretty much almost all frameworks I use in programming uses the height and width when identifying a flat dimension (without Z axis), but when in math, a 2 axis object is always measured by length and ...
1
vote
3answers
352 views

Is Diff a well understood term, or should I name it Differentiate?

I have a class which checks for differences. I could call this class ViolationDiffer public IEnumerable<ViolationChange> Diff( IEnumerable<Violation> old, IEnumerable&...
0
votes
1answer
1k views

Node.js script const variables in SCREAMING_SNAKE_CASE or camelCase

TL/DR: When requiring another script in Node.js and defining it as a const should the variable name still be in camelCase like it was usual with var or should it instead be in SCREAMING_SNAKE_CASE as ...
29
votes
2answers
7k views

Why does software use the Win32 name?

If a software/library has some support for the Windows platform they almost always name their directories and variables as win32. This is most prevalent in C/C++ projects. Even the MinGW project's ...
2
votes
3answers
285 views

Differentiate between variables used and not used in properties

I am learning about c# and I am a little confused about (non-automatic)properties and the local variable that the property uses. When I use properties, I put an underscore for all the private ...
0
votes
3answers
306 views

Code pattern to have the least possible code complexity (Javascript)

I've been looking for the ideal coding patterns used to score well in a Cyclomatic Complexity. Of course, code will be subject to change according to what is being developed but regardless the ...
1
vote
1answer
150 views

How to write Readable Comment when we have to deal with IDs?

How to write Readable Comment when we have to deal with IDs? I will explain this with example. +---------------+-----------------+ | permission_id | permission_name | +---------------+--------------...
0
votes
1answer
101 views

For Qt, or C++, do modern standards or practices exist for designing Run Configuration files for your programs? [closed]

Backstory I am building a daemon that is to be run in the background on systems based on X11. As of right now, the settings are hardcoded, and that obviously needs to change. As such, I plan to ...
0
votes
1answer
218 views

Which is better in terms of performance (bool01==bool02) vs (bool01 && bool02) [duplicate]

Which of these two is the better way of doing the same thing - public void someMethod(String s, boolean bool02){ boolean bool01 = s!=null; if(bool01==bool02){ doSomething(); } } OR public ...
1
vote
1answer
111 views

Is it standard to log each case of a switch statement?

Some code I wrote was sent back to me during peer review, telling me to add logging to the start of each case in a switch statement in a servlet (Java, if that matters), so if something goes wrong, we ...
10
votes
4answers
944 views

Reworking a function returning an integer code that represents many different statuses

I've inherited some awful code that I've included a short sample of below. Is there a name for this particular anti-pattern? What are some recommendations for refactoring this? // 0=Need to log in / ...
4
votes
2answers
185 views

Are there any grammatic conventions on naming functions?

For example, I have a Selenium WebDriver and as part of my initialization I would like to check if I am able to instantiate it and start up browser. I can't come up with a proper name. Is there any ...
14
votes
8answers
7k views

C# - Why are prefixes on fields discouraged?

Back in the old days, we did Hungarian notation. That's now considered passé, and for the most part I don't use it anymore, but I still find use for the m_ prefix to indicate member fields. For me, ...