42
votes
Accepted
Why is array access not an infix operator?
The answer to "why" questions is often partly historical - unless there is a good reason to be different, following existing conventions helps limit a new language's "strangeness budget&...
32
votes
Why is array access not an infix operator?
There are a couple of arguments in favour of the x[y] syntax for arrays, over an infix operator.
One is that we want array access to bind the left operand more ...
26
votes
Can "no cyclic data structures" be enforced at compile time?
Yes, it can be. There are three simple ways:
Ban recursive type definitions, so e.g. a Foo can't have a field of type Foo, or a ...
23
votes
Why is array access not an infix operator?
it is, sometimes
In Haskell, array access is the binary operator !!.
In APL, one of the ways of doing array access is the dyadic function ...
11
votes
Accepted
What are the downsides of having no syntactic sugar for data collections?
Why would a language prefer to mark its' builtin primitives as first-class citizens with specific syntax for them?
Why have special syntax for common data structures? Because it’s convenient! No more ...
10
votes
Accepted
What are the implications of a 'packed' keyword/feature?
Padding and Packing
The layout of structures is defined by the ABI (Application Binary Interface). The typical mindset of an ABI designer is mechanical sympathy, with an eye towards performance (speed)...
10
votes
Would a structure ever require padding beyond what is required to align the members?
There's two questions into one here:
Would a structure ever require padding beyond what is required to align the members?
Maybe? That is an implementation detail, and C tells you it doesn't care ...
10
votes
Can "no cyclic data structures" be enforced at compile time?
Yes, we do this in Roc. There's no way to express a cyclic data structure in Roc, and we rely on this invariant for our memory management design: we use automatic reference counting with no cycle ...
9
votes
What are the implications of a 'packed' keyword/feature?
According to “The Lost Art of Structure Packing” by Eric S. Raymond, structure packing can slow down your program or worse:
The first thing to understand is that, on modern processors, the way your ...
8
votes
Accepted
Distinguishing classes from structures
Not Necessarily
Lots of modern languages agree with you, which is why we're seeing the rise of the concept called a data class. Basically, rather than having two completely disjoint concepts for "...
7
votes
Would a structure ever require padding beyond what is required to align the members?
One possible use case for more complex padding is for something like OpenCL, targeting GPUs with peculiar local memory layouts, where you may want to ensure that threads (warps, whatever else they're ...
7
votes
Accepted
Would a structure ever require padding beyond what is required to align the members?
In some applications, complete ABI stability is required - for example, the syscall interface to the Linux kernel. This means you can't change the size of a struct, because it would break old code. ...
7
votes
What are the pros and cons of having a unique type for generators?
Yes, in the context of a language that isn't otherwise lazy or memoised.
There are real semantic differences between generators and lists: you can index into a list arbitrarily, and retrieve a value ...
6
votes
Can "no cyclic data structures" be enforced at compile time?
Yes...
... at least, if you add some stronger limiting conditions on what the language can do.
One way to prevent cyclic data structures is to make all values immutable. This works because cycles are ...
6
votes
Can "no cyclic data structures" be enforced at compile time?
Many people have noted you can remove mutability, which gets rid of cycles. However, it’s not all mutability which causes cycle, just aliased mutability.
For instance, in safe rust you can’t form ...
6
votes
What are the implications of a 'packed' keyword/feature?
Generally, compilers optimise for program speed rather than memory use. This is because in typical desktop and laptop PCs, memory is abundant, and a suboptimal struct layout won't waste that much ...
6
votes
Distinguishing classes from structures
Keep in mind C++ has a heavy C inheritance. A class defined as struct in a C++ program, if it has no special features like virtual functions, is indistinguishable in memory from a PODS (Plain Old Data ...
5
votes
Distinguishing classes from structures
For the most part, this distinction tends to reflect the history and evolution of languages.
Structures are a simple feature that most languages have had since they were originally designed. They ...
5
votes
What are the implications of a 'packed' keyword/feature?
There's not really any need for this feature, and using it could cause performance issues (e.g. requiring extra memory fetches and realignment for each item, or even a memory fault).
In situations ...
5
votes
What are the implications of a 'packed' keyword/feature?
I see no harm in including this as an optional feature, but be aware of performance issues that could be caused using this.
Many processors do not support many operations on non-aligned data. For ...
5
votes
Would a structure ever require padding beyond what is required to align the members?
A few ideas:
Some implementations might wish to have all struct fields in the order they're declared, e.g. for binary compatibility with other programs, file formats or network protocols. This might ...
4
votes
Should functions like filter and map be members of a class or top-level functions?
Top-level advantages:
Global Availability: Since these functions are available globally, you can directly use them on any iterable without the need to import specific modules or extend the iterable ...
4
votes
Distinguishing classes from structures
If the difference really is very small then there does, as you say seem little purpose in distinguishing. Sometimes the difference may be historical. But the difference may not be small.
Common Lisp ...
4
votes
Accepted
Representing multiple alternative ASTs in one structure
Perhaps you’re thinking of equality saturation?
It doesn’t quite match the description in your question—it isn’t really about multiple AST “representations” per se, but rather multiple terms with ...
3
votes
Distinguishing classes from structures
Depends on the (runtime) semantic difference
I think it depends on whether the semantic difference is big enough.
The distinction between private and ...
3
votes
Distinguishing classes from structures
If we declare that the construct has no methods, private fields (so no hidden internal state) or inheritance, this has the same effect as using bool as a synonym ...
3
votes
What are the downsides of having no syntactic sugar for data collections?
The benefits to syntactic sugar for primitives is obvious; it's much easier to construct common collections, and much more readable too.
Disadvantages are less obvious:
Avoiding being opinionated
...
3
votes
Why are type theorhetic data structures rarer (than sets) if they are fundamental?
I think you're confused a lot about the meaning of the word "Set". In CS, Sets are special Lists with extra properties, as you pointed out. That's simply it. This is close to how they're ...
3
votes
Would a structure ever require padding beyond what is required to align the members?
On some platforms, there may be benefits to padding array elements to a power-of-two size, and on some others (though probably mostly obsolete ones by now) there may be advantages to padding arrays ...
3
votes
Would a structure ever require padding beyond what is required to align the members?
Consider:
typedef struct {
double d;
char c;
} S;
static S a[2];
The address of a[1] must be on a double boundary.
<...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
data-structures × 14types × 2
optimization × 2
compilers × 2
syntax × 1
c × 1
operators × 1
garbage-collection × 1
haskell × 1
language-design × 1
immutable × 1
compiler-checks × 1
object-oriented × 1
functional-programming × 1
abstract-syntax-tree × 1
standard-library × 1
classes × 1
interfaces × 1
iterators × 1
generators × 1
algebraic-data-types × 1
struct-packing × 1
lazy-evaluation × 1