All Questions

Filter by
Sorted by
Tagged with
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?
1
vote
3answers
217 views

What is a good method/practice I can employ to keep identical code snippits in two places in sync? Also, help documenting functionals

If I could get some input on the design of this, I would be grateful as well. Note that I'm programming in python. There's a function F that takes lots of data, runs some analysis on it (taking ...
1
vote
1answer
162 views

Using “On” at the start of a method name

From what I've observed, methods that start with the word "On" fall into two categories: A base class that defines an event will expose a protected method whose name starts with "On" followed by the ...
3
votes
1answer
129 views

How hard should I try to write idiomatic code in a polyglot environment?

I work on a small team (2 primaries with one or two other occasional contributors) on a project/product that spans a number of separate platforms. We do embedded firmware in straight C on Arm0 chips. ...
2
votes
5answers
600 views

What should a constructor contain?

What should a constructor contain? In both cases, all three arguments are needed for the class to work. Which approach is better and why? 1) class Language { LanguageRepository ...
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 ...
-1
votes
1answer
627 views

coding practices: return vs else [closed]

Which coding style is considered better practice? if-return: function fn { if (condition) { /* if true: insert code here */ return; } /* ...
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 ...
1
vote
1answer
109 views

Should a loop be nested inside an unchanging conditional?

I was reviewing some old code and stumbled upon a loop nested inside a conditional like this: std::cin >> number; //number is used elsewhere, so should be preserved if (number <= 10) for ...
8
votes
7answers
10k views

Why unused variables is such an issue?

I was cleaning unused variables warnings one day, and I started to ponder, what exactly is the problem about them? In fact, some of them even help in debugging (e.g. inspect exception details, or ...
4
votes
2answers
230 views

Using tiny number of classes from a large library

I wrote a utils library (5 KLOC) that a lot of my projects use. I've also written a very small project (150 LOC) that needs just 1 or 2 of the classes in the utils library. I really don't want to add ...
5
votes
3answers
272 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 ...
10
votes
5answers
710 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 ...
6
votes
5answers
2k 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 ...
34
votes
8answers
5k 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'){ ...
5
votes
1answer
155 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: ...
3
votes
2answers
310 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 ...
2
votes
1answer
231 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()){ ...
-2
votes
4answers
5k 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 ...
3
votes
1answer
233 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,...
5
votes
4answers
2k views

Magic numbers, locality and readability

Lately I've found myself inserting magic numbers into code to make it more readable. I've done this in situations where the magic number is only used once and its purpose is obvious from the context. ...
2
votes
4answers
1k views

Are some people just unable to code? [closed]

So for the past year or so, I've been trying to self-teach myself programming. The problem is, every time I start to try and teach myself (like on Codecademy and such) I start off great and then ...
-6
votes
2answers
249 views

Should one always start a boolean with “is” or “has”? Or write it as it makes more sense grammatically?

Examples: isKeyValid -> keyIsValid hasPostThumbnail -> postHasThumbnail The first case is easier to remember (convention). The second is easier/more natural to read. Which should I use?
3
votes
2answers
253 views

Using “partial” type to shorten main class file

Is it a normal practice, or a sign of a bad design? For example I have a function that loads prefabs in a main logic class nearing 200 lines, and I can either move it out into a separate file ...
5
votes
1answer
2k views

Common imports between many scripts in Python project

I'm writing an automated installation script for a bunch of software, in Python. The purpose is for the script to fetch compressed files from a directory and install/configure each utility or ...
4
votes
3answers
4k 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): ...
45
votes
8answers
10k 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 ...
13
votes
1answer
3k views

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

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()" ng-...
46
votes
6answers
12k 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
0answers
131 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 '...
0
votes
2answers
2k views

guideline on void methods that do not throw exceptions

In our codebase I saw a method that is similar to following: public void doSomething() { try { ... } catch (Exception e) { ... //log something ... } } The ...
1
vote
2answers
1k views

Non-printable characters and editors

Today I was presented with a very nasty problem and I do not quite know where to ask this but hope here is ok. So I have the following string: "\0" (at least that's how it looks in visual studio). If ...
1
vote
1answer
643 views

How to name variables without plural in a for-each loop? [closed]

How do you name loop variables when the list item is named after something without a plural? For instance (in python): [x for x in sheep]. x is not a great name, but sheep have/has no plural that ...
33
votes
8answers
9k views

Is throwing an exception an anti-pattern here?

I just had a discussion over a design choice after a code review. I wonder what your opinions are. There's this Preferences class, which is a bucket for key-value pairs. Null values are legal (that'...
-2
votes
2answers
196 views

which is a better practice one method that does everything or a series of different methods?

I'm working with asp.net and c# Lets say I have a bunch of drop-downs and I want to bind data from a database, is it better to make a master-bind method that loops each one and gets the parameters to ...
11
votes
4answers
468 views

When should a private method take the public route to access private data?

When should a private method take the public route to access private data? For example, if I had this immutable 'multiplier' class (a bit contrived, I know): class Multiplier { public: Multiplier(...
3
votes
4answers
2k views

How does a developer code in anticipation of change? [closed]

I ask this question based on the fact that currently my environment is under constant change due to the type of work we do. We do not always work on a project bases we often have smaller changes that ...
6
votes
3answers
4k views

Nullable enumeration values vs. “NoValue” or “Undefined”, etc

I often write code which translates entities in the database to domain objects. These entities often have fields which are constrained and translate to enumerations in the domain objects. In some ...
4
votes
1answer
1k views

Redundant ElseIf-Else Blocks [duplicate]

These types of if-elseif-else blocks appear all over the place, and in no small number (so the less the better). Every time I have to think and decide: Do I want the simpler or the more thorough of ...
0
votes
4answers
359 views

How can if (sscanf(buf, “%i”, &mode) != 1 || TRUE) be rewritten to if (TRUE)?

I got lost in the opening of this post on reddit. How can if (sscanf(buf, "%i", &mode) != 1 || TRUE) be rewritten to if (TRUE)? Does this assume that the sscanf never fails?
3
votes
1answer
425 views

MVC Controller - keeping methods small

I'm reading uncle Bob's Clean Code and it completely revolutionizes my programming style. In this book author claims that best methods are small methods. What about controller's action methods in ...
8
votes
4answers
4k views

Should you ever use private on fields and methods in C#?

I am somewhat new to C# and just found out that: in C# all of the fields and methods in a class are default private. Meaning that this: class MyClass { string myString } is the same as: class ...
54
votes
6answers
4k views

Is making a small change, testing it, then “rinse and repeat”, a bad habit?

I am a programmer with a number of years of experience. I realized I got a certain habit. I'm not sure whether it's really a bad habit or not. I get a list of tasks to perform for a solution, even ...
3
votes
3answers
754 views

Refactoring previous intern's noodle code with future interns in mind [duplicate]

Background I've run across this problem as I am currently an intern at a large company's local software division. I have been given the task of extending a project that several previous interns have ...
3
votes
1answer
2k views

Is serialization better done in instance methods or static methods

Say I have a class workStockItem, that I wish to serialize. Which is the better style? using a static method or using a non-static method (maybe even implemented as a property as seen below) ...
3
votes
1answer
148 views

equivalence in callback and non-callback javascript

I'm pretty sure that the following two snippets are equivalent but I wanted to double check: CALLBACK STYLE function foo(input, callback) { // do stuff with input callback(); } function ...
0
votes
1answer
130 views

Which is preferred coding style to validate and return from a method [duplicate]

Which of the below is a preferred coding style (in c# .net) public void DoWork(Employee employee) { if(employee == null) return; if(!string.IsNullOrEmpty(employee.Name)) return; // Do ...
3
votes
3answers
4k views

articles in variable names and hard-coding strings

re-edited by author: no this is not 2 questions. This is one question about code review questions containing two separate points. Please do not edit my question. For naming variables, the two sides ...
3
votes
2answers
2k views

Is repeating links to the same class in a single javadoc comment a bad practice?

I'm currently writing an API and its documentation. For example I have something like this: public interface Event { } public interface Process { } public interface EventProcessor { /** * ...
1
vote
5answers
322 views

Is it a good practice to write a method that gets something and checks the value? [duplicate]

Occassinally I have to write methods like this: string GetReportOutputDirectoryAndMakeSureExist() { string path = Path.Combine ( ... ) //whatever logic if(!Directory.Exists(path)) Directory....