140
votes
Before OOP, were data structure members left public?
OOP did not invent encapsulation and is not synonymous with encapsulation. Many OOP languages do not have C++/Java style access modifiers. Many non-OOP languages have various techniques available to ...
111
votes
Why do so many standards for JSON API response formats contain a "success" property in the response body instead of just using HTTP status codes?
Many people take HTTP status code as “successful communication with the server”.
Now if a customer wants to buy a US$200 item and has only US$100 in their account, the JSON response will be “failure, ...
94
votes
Accepted
Why is using MySQL for a dictionary website a bad idea?
I can't tell you why it's a bad idea. I can tell you a bunch of reasons why a relational database is a good idea though.
Remember that not everyone consults a dictionary for a definition. More times ...
85
votes
Accepted
How should I store "unknown" and "missing" values in a variable, while still retaining the difference between "unknown" and "missing"?
The common way to do this, at least with functional languages is to use a discriminated union. This is then a value that is one of a valid int, a value that denotes "missing" or a value that denotes "...
68
votes
Why do many functions that return structures in C, actually return pointers to structures?
There are several practical reasons why functions like fopen return pointers to instead of instances of struct types:
You want to hide the representation of the struct type from the user;
You're ...
66
votes
Accepted
Why are data classes considered a code smell?
There is absolutely nothing wrong with having pure data objects. The author of the piece quite frankly doesn't know what he's talking about.
Such thinking stems from an old, failed, idea that "true ...
59
votes
Accepted
What is the most efficient way to store a numeric range?
Just count the number of possible ranges. There are 256 ranges with lower bound 0 (0-0, 0-1, ... 0-254, 0-255), 255 ranges with lower bound 1, ... and finally 1 range with lower bound 255 (255-255). ...
58
votes
How should I store "unknown" and "missing" values in a variable, while still retaining the difference between "unknown" and "missing"?
If you do not already know what a monad is, today would be a great day to learn. I have a gentle introduction for OO programmers here:
https://ericlippert.com/2013/02/21/monads-part-one/
Your ...
58
votes
Accepted
Why do so many standards for JSON API response formats contain a "success" property in the response body instead of just using HTTP status codes?
A few potential reasons why you may wish to do this are:
the fact that some HTTP clients treat anything other than 2xx as an "exception" to be thrown, which can hide differences between ...
40
votes
Why do many functions that return structures in C, actually return pointers to structures?
There are two ways of "returning a structure." You can return a copy of the data, or you can return a reference (pointer) to it. It's generally preferred to return (and pass around in general) a ...
37
votes
Accepted
What difference is there between using a struct and a std::pair?
Choice 1 is ok for small "used only once" things. Essentially std::pair is still a struct.
As stated by this comment choice 1 will lead to really ugly code somewhere down the rabbit hole like thing....
37
votes
Accepted
How to represent a set in JSON?
Well, you can't. As you said, you can represent arrays and dictionaries. You have two choices.
Represent the set as an array. Advantage: Converting from set to array and back is usually easy. ...
36
votes
How is polymorphism used in the real world?
Stream is great example of polymorphism.
Stream represents a "sequence of bytes that can be read or written". But this sequence can come from file, memory, or many kinds of network connections. Or it ...
34
votes
Is there a common term for a fixed-length, fifo, "push through" array or list?
This sounds a lot like a circular buffer or ring buffer. It meets most of the criteria:
It has a fixed size of items.
They don't have to be a specific value at the start, but they could be ...
33
votes
Methods to increase the amount of data sent in a packet
The main method to reduce your packet size is to use a binary encoding of your data.
If your sensors produce the data in a binary format, note the specifications of the format, such as the number of ...
31
votes
Before OOP, were data structure members left public?
First, being procedural versus object oriented has nothing to do with public vs private. Plenty of object oriented languages have no notion of access control.
Secondly, in "C" - which most people ...
29
votes
Accepted
Is it good practice to wrap a related set of properties into its own struct/class?
You will either need
zero of a thing,
one of a thing, or
an arbitrary number of the thing.
I'm shocked that your design predicts that the number of needed links will always be three and that you ...
27
votes
Why is using MySQL for a dictionary website a bad idea?
If you go with the key-value store (which offers you a more impoverished programming model) and it turns out you need more structure (in your case, say, adding a third language), or you need to do ...
23
votes
Accepted
Is there a tree data structure with multiple root nodes?
You are looking for a kind of Directed Acyclic Graph (DAG). These graphs do not have a root node. However, the nodes have a partial order. I.e. when we look at two nodes we can sometimes tell which ...
21
votes
EAV - is it really bad in all scenarios?
6 years later
Now that JSON in Postgres is here, we have another option, for those who are using Postgres. If you only want to attach some extra data to a product, then your needs are fairly simple. ...
20
votes
Is there a common term for a fixed-length, fifo, "push through" array or list?
Like the other answer suggests, a fixed-length fifo queue is a ring buffer, although usually writing past the capacity will be prevented, instead of overwriting the next element.
in fact, it's not ...
20
votes
How to ensure data consistency in system with multiple databases?
There are no easy solutions.
Distributed consistency is fundamentally difficult, with some hard limits to what is possible. See the CAP theorem and Fallacies of distributed computing. And doing ...
19
votes
Accepted
What makes some things easier to parse than others?
This topic is very complex. You can google for parser algorithms and you'll get plenty of detailed material.
In general:
The fewer ambiguities must be resolved, the faster the parsing
process.
The ...
19
votes
Accepted
Is storing a list of strings in single database field a bad idea? Why?
The datamodel isn't normalised; to be so it would need a separate table as you say. In that regard, it's not particularly good datamodelling practice.
Whether it was done for a good reason or not is ...
18
votes
Accepted
Why do we need stacks and queues?
Stacks and queues are ways of working with contiguous memory. Linked lists are not. Now sure, any problem that you can solve with one structure you could solve with another and slap enough ...
18
votes
What difference is there between using a struct and a std::pair?
Performance:
It depends.
In your particular case there will be no performance difference because the two will be similarly laid out in memory.
In a very specific case (if you were using an empty ...
18
votes
How should I store "unknown" and "missing" values in a variable, while still retaining the difference between "unknown" and "missing"?
I think that in this case a variation on a Null Object Pattern would be useful:
public class Measurement
{
private int value;
private bool isUnknown = false;
private bool isMissing = ...
18
votes
Why do so many standards for JSON API response formats contain a "success" property in the response body instead of just using HTTP status codes?
There are inherent shortcomings in trying to fit a nuanced, complete API into the limitations of HTTP. The above examples provide some good points to why that's the case.
Here's another scenario we ...
18
votes
Methods to increase the amount of data sent in a packet
With all due respect, your data is boring.
So take advantage of that.
Leverage its very boring nature.
I recommend you send such data in routine Update messages.
And that you occasionally send ...
17
votes
Why are data classes considered a code smell?
There is absolutely nothing wrong with having pure data objects. The author has an opinion not shared by the software developers I know.
Especially for database mapping you in general have entity ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
data-structures × 906algorithms × 176
c++ × 80
java × 74
database × 63
database-design × 62
design × 55
c# × 49
design-patterns × 49
trees × 47
c × 45
data × 42
python × 27
object-oriented × 24
architecture × 23
binary-tree × 22
javascript × 21
performance × 20
functional-programming × 20
graph × 20
object-oriented-design × 19
array × 18
json × 17
hashing × 17
php × 16