Skip to main content

Questions tagged [arrays]

For questions about the implementation or design of arrays within a programming language, including C++ vectors, Java Lists, or other types of dynamic arrays.

Filter by
Sorted by
Tagged with
3 votes
0 answers
174 views

Languages in which array types must be declared before usage

Some languages require array types to be declared before an object of that type can be declared. In Ada, for example: ...
QF0's user avatar
  • 131
1 vote
3 answers
330 views

Is there any way a Java-like language could implement immutable primitive arrays without incurring performance penalties?

I asked: What prevents Java from having immutable primitive arrays? a while back and got an answer: Because immutable primitive arrays would typically require checking some immutable flag every time a ...
CPlus's user avatar
  • 8,301
2 votes
1 answer
258 views

Implementing a Array programming language in C. What is the best and most efficient struct for the arrays? [closed]

...
rapasite's user avatar
9 votes
1 answer
2k views

In Python, why isn't it a syntax error when a list of strings is defined without comma separators?

When coding in Python, I found that defining a list of strings without separating the strings with a comma is not a syntax error. When running this code: ...
Redz's user avatar
  • 1,058
6 votes
3 answers
819 views

Why might a language avoid reallocation?

In Java, the size of arrays are immutable. However, to my understanding, they are still allocated on the heap, because Java allocates almost everything on the heap. Even then, Java arrays are still ...
CPlus's user avatar
  • 8,301
3 votes
5 answers
732 views

To what degree is it practical to let objects be stored packed? [closed]

Let's say I want my compiler to store objects packed (data and collection members aligned to non-word boundaries). Situation #1: I want to store an array of booleans. A few languages already let the ...
Dannyu NDos's user avatar
5 votes
2 answers
307 views

Why would Short String Optimization not apply to dynamic arrays?

Short string optimization is the optimization that sufficiently short strings have their data stored inline rather than an external buffer, so the string type ends up being a union. Swift does this, ...
Bbrk24's user avatar
  • 9,057
4 votes
0 answers
170 views

Do any languages provide arrays that are always powers of 2 in length?

In the early 1970s, I had university a co-op job at a place where one of the main languages used was like a glorified calculator. It provided two stacks, and all variables and operators were a single ...
Ray Butterworth's user avatar
11 votes
3 answers
306 views

How can a language statically ensure a required index exists in a list?

Suppose a language has a conventional list data structure that contains some dynamic number of values indexed sequentially. Some operations to access a value from the list require that a certain index ...
Michael Homer's user avatar
  • 13k
17 votes
3 answers
1k views

What are the implications of implementing variable-length arrays?

At first C did not have variable-length arrays; all array sizes must be compile times constants. Then, in C99, variable-length arrays, a controversial addition, were added, permitting runtime-sized ...
CPlus's user avatar
  • 8,301
4 votes
1 answer
152 views

What are some good syntaxes for tensor initialisation?

Inspired by this question - What are the disadvantages of being able to define a matrix without typing any words? There is a more general question of what are some syntaxes for initialising tensors ...
Bruce Adams's user avatar
  • 2,843
7 votes
10 answers
340 views

What are some syntax options for iterating over arrays?

What are some different syntax choices for loops that iterate over arrays? Of course, there is the common for loop: ...
cocomac's user avatar
  • 575
12 votes
6 answers
427 views

What are the disadvantages of this far-fetched idea: All integers can be treated as boolean arrays?

I do not know of any languages that support this idea but I just thought that since numbers are just bits, why should we not be able to access those bits directly? In most languages such as C or C++, ...
CPlus's user avatar
  • 8,301
-5 votes
1 answer
453 views

What are the pros and cons of implementing indexed for loops? [duplicate]

When iterating over an array you can use an indexed for loop, like so: ...
Redz's user avatar
  • 1,058
1 vote
2 answers
174 views

What should a variable-size contiguous collection be called?

Different languages have different names for the same thing. Off the top of my head, there's: C++ vector and Rust Vec Java <...
Bbrk24's user avatar
  • 9,057
6 votes
3 answers
173 views

How could C implement first class arrays?

C does not have first class arrays that can be assigned (copied) or returned from functions directly. In such a low level language where arrays are essentially pointers to the first value. This way, ...
CPlus's user avatar
  • 8,301
14 votes
12 answers
1k views

What are the advantages of strings and character arrays being different?

In many languages such as Java, strings and character arrays are distinct types. In Java one must use toCharArray() in order to use array semantics on strings. In C,...
CPlus's user avatar
  • 8,301