100
votes
Why are bit masks called "masks" and what purpose do they serve?
A mask (of the facial variety) is something that covers up some parts of your face and lets other parts show through. The terminology is used by analogy in computing: a bitmask covers up (filters out)...
57
votes
Best practice for redundant conditions in if-elif-else statements
Even Case 1 can have unexpected behaviour. The value of n that worries me is NaN.
n = float('nan')
if n == 0:
doThis() # Not triggered
elif n < 0:
doThat() # Not triggered
elif n > 0:
...
55
votes
Why are bit masks called "masks" and what purpose do they serve?
A bit mask is used to mask some bits of a bit field while exposing others:
initial value: 011011001
bit mask.....: 111110000
result value.: 011010000
This has been used before computing in ...
46
votes
Accepted
I am spending more time installing software than coding. Why?
What am I doing wrong?
You're trying to develop in an environment where you're also the sysadmin, devops and the local technical product owner for every pip package you use - and you're assuming that ...
45
votes
Does it make sense to keep two different versions of code?
As a professional software engineer writing embedded software (i.e., the software itself is not a product, but it is part of a physical product), nearly all the time I am working with and extending an ...
39
votes
Why are bit masks called "masks" and what purpose do they serve?
Bitmasks are terribly old. I haven't been able to find a reference to the first one, but they were certainly popular by the advent of 8-bit processors, and likely were also used in 4-bit processors.
...
25
votes
Accepted
Best practice for redundant conditions in if-elif-else statements
Short answer
I would argue that there is no singular correct answer to this question.
It depends on what you want to have happen when one of the above cases changes. Are you assuming that the last ...
22
votes
Does it make sense to keep two different versions of code?
Personally, I can imagine where writing and keeping two software codes makes sense. For example, one wants to have a test version that simply implements all the desired functionality and use that one ...
21
votes
Does it make sense to keep two different versions of code?
We actively do this. Our reference code base follows academic papers, and it's easy to show a one-to-one mapping. This gives us the confidence that the results are correct. It's rather slow, though - ...
16
votes
Why do or should programmers save data in text based formats like JSON or XML instead of binary?
JSON and XML are less efficient than pure binary, but what you aren't considering is that they (JSON/XML, and some other formats like YAML) are standardised, while binary isn't - different systems, ...
16
votes
Does it make sense to keep two different versions of code?
One thing I would add here is that on the performance topic, I have encountered in my career far more code that some engineer thought might be performance critical and over-engineered an unreadable ...
12
votes
Global state variables vs constructor parameter passing
Performance-wise only please.
You have already made the wrong decision, right there. This is called "premature optimisation" and it's frowned upon, for good reasons.
The correct question to be asking ...
10
votes
Accepted
Does wrapping functions/'things' in classes reduce efficiency?
This statement is either wrong or incomplete:
Calling a non-virtual member function requires exactly the same code as calling a free function with one additional pointer argument. That's peanuts.
...
9
votes
Why are bit masks called "masks" and what purpose do they serve?
A bit mask is similar to screen printing. You select some certain bit position to be taken over into the result:
source value = 42 -> 00101010b
mask = 51 -> 00110011b
result 42&51 = ...
9
votes
Accepted
Avoiding if statements in Nested FOR loops
One way to avoid those ifs inside the loops is to put them outside, by deciding which functions to call in advance:
//set the values of conditionA, conditionB and conditionC;
functionA = conditionA ?...
9
votes
Why do or should programmers save data in text based formats like JSON or XML instead of binary?
They're human readable: you can read and write them in plain text editor
They're standardized: which means there are a wealth of off the shelf tooling available to work with them
They're easy: you don'...
9
votes
Accepted
How is it possible to have an efficient edit-compile-try cycle on large codebases?
Even in small projects, when you do a change, you don't recompile anything. In fact, the build is often performed in two steps: compilation and linking. If you modify two files which don't impact ...
8
votes
Accepted
Reducing Redundant Calculations
Calculating the vector magnitude should be a method of the vector class. Then it can cache and reuse the result as necessary or advisable. Burdening higher-level logic with micro-decisions like this ...
8
votes
Accepted
Do blockchains provide any improvement over conventional systems/frameworks when decentralization is not required?
a COMPANY (therefore not decentralized) wanted to make a product or system that did XYZ, what benefits does blockchain provide over conventional frameworks?
In many cases, nothing whatsoever. And a ...
8
votes
Does it make sense to keep two different versions of code?
There are several more case not covered so far when several versions of the code maintained for some time or forever: reference implementations, dark launches, backward compatibility and versioned ...
7
votes
Accepted
Is it any more efficient to reuse a variable than to create a new object?
This is not a correct way to think about performance. As a result, you'll make your code harder to follow and more error prone, while having no gains in performance.
The correct way consists of ...
6
votes
Accepted
Why are (hexadecimal) hashed passwords/cookies/.. saved as strings in databases?
Firstly, hexadecimal is not really a storage format... it is a display format. You can choose to store hexadecimal strings in a database, if you wish, but the more natural (and more common) technique ...
6
votes
Why do or should programmers save data in text based formats like JSON or XML instead of binary?
I suspect this question is posed more as rhetoric than from genuine puzzlement.
First off it must be acknowledged that binary formats are long-established and a perfectly legitimate option for saving ...
5
votes
Effecient algorithm for data deduplication in procedural code
It seems to me that the only way you can really change the time complexity is to start to turn the Jaro-Winkler algorithm 'inside-out' by collecting statistics on each value that are relevant to the ...
5
votes
When building time takes so long, how to improve engineer's efficiency?
One thing would be to reevaluate how much you are relying on templates. In typical C++ projects, creating your own templates is relatively rare.
Next thing is to make sure you are generating ...
5
votes
Why do or should programmers save data in text based formats like JSON or XML instead of binary?
I should add a very pertinent war story.
Way back in time Borland released Delphi 1.0 with the screen design files saved in binary format. This was a minor disaster.
Delphi was not itself bug free. ...
4
votes
What is difference between assigning to auto-Implemented properties VS their backing fields within the class
If you assign directly to a backing field, you can be certain it will work.
If you assign using the property that wraps the backing field, you can't be sure it will work. If the property is ...
4
votes
In which order perform tasks from big backlog
One of the most important things to do with a backlog is groom it. You should go through the backlog and prioritize the tasks.
It can seem overwhelming when the backlog grows faster then it gets ...
4
votes
How can I efficiently make changes to a large module without having to re-run every time?
Divide and Conquor
This large module can probably be broken down into smaller more easily tested functions.
Those functions probably do not provide end user behaviour, but you can at least nail down ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
efficiency × 183algorithms × 34
design × 12
c# × 12
performance × 12
java × 10
productivity × 9
database × 8
programming-practices × 8
c × 8
data-structures × 8
mysql × 8
sorting × 8
c++ × 7
php × 7
complexity × 7
optimization × 6
speed × 6
python × 5
programming-languages × 5
readability × 5
web-development × 4
database-design × 4
coding-style × 4
sql × 4