Skip to main content
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&...
IMSoP's user avatar
  • 2,577
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 ...
kaya3's user avatar
  • 20.8k
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 ...
kaya3's user avatar
  • 20.8k
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 ...
RubenVerg's user avatar
  • 1,661
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 ...
Alexis King's user avatar
  • 10.4k
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)...
Matthieu M.'s user avatar
  • 3,549
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 ...
Longinus's user avatar
  • 1,883
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 ...
rtfeldman's user avatar
  • 101
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 ...
Brandon Dyck's user avatar
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 "...
Silvio Mayolo's user avatar
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 ...
SK-logic's user avatar
  • 1,340
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. ...
pxeger's user avatar
  • 848
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 ...
Michael Homer's user avatar
  • 13.6k
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 ...
DLosc's user avatar
  • 501
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 ...
Charlie Lidbury's user avatar
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 ...
kaya3's user avatar
  • 20.8k
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 ...
kouta-kun's user avatar
  • 1,668
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 ...
Barmar's user avatar
  • 1,980
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 ...
Ray Butterworth's user avatar
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 ...
mousetail 'he-him''s user avatar
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 ...
kaya3's user avatar
  • 20.8k
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 ...
The Thonnu's user avatar
  • 1,566
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 ...
ignis volens's user avatar
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 ...
Alexis King's user avatar
  • 10.4k
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 ...
Aster's user avatar
  • 3,308
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 ...
Audrius Meškauskas's user avatar
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 ...
mousetail 'he-him''s user avatar
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 ...
ice1000's user avatar
  • 2,694
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 ...
supercat's user avatar
  • 1,996
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. <...
Ray Butterworth's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible