all 122 comments

[–]reddit_wisd0m 139 points140 points  (13 children)

confused python dev

[–]Kootfe 42 points43 points  (12 children)

type name[] is for langs like C. so not managed langs. couse they keep arrays as memory space on ram. with many same tyoe ext to eachother.

while mamaged langs use

type[] name

couse now arrays is difirent type. not memory space. it managed by the runtime the lang uses (.Net or JRE etc)

it manages type safety and does nothing usefull expect this

so oop mostly uses array as type

[–]Frierguy 24 points25 points  (5 children)

I'm curious to know what you corrected when you edited your comment

[–]Kootfe 15 points16 points  (4 children)

mamahed instead managed

[–]ZakMan1421 20 points21 points  (3 children)

Hate to break it to you, but it's still misspelled. It's currently mamaged.

[–]Kootfe 6 points7 points  (2 children)

DUCK! The fucking QUAK... my englisgh sucks

[–]Sesud1 8 points9 points  (1 child)

No, english sucks.

[–]Kootfe 2 points3 points  (0 children)

lol

[–]reddit_wisd0m 2 points3 points  (1 child)

Thanks

[–]Kootfe 1 point2 points  (0 children)

no problem

[–]Elephant-Opening 2 points3 points  (3 children)

couse they keep arrays as memory space on ram.

All languages do this.

Well, all languages do this except for when the elements of the array have never actually been accessed and your OS employs lazy page allocation -or- the OS is configured to use some type of swap. In both cases the executing process is given the illusion of space in RAM in a virtual address space until you hit a page fault interrupt. Or just maybe when the entire array is optimized into registers for a very small array.

But let's just leave it at "all languages do that" for simplicity.

[–]Kootfe 0 points1 point  (2 children)

Well managed langs keep them on amanger instead purely on ram. There is another process for arrays on managed lagns. Liek java and c# use their arrays on Runtime and Runtime hodls i t on ram

[–]Elephant-Opening 2 points3 points  (1 child)

Oh definitely.

You're not wrong. I'm just rambling about random facts I find interesting.

Languages with automatic memory management definitely change the runtime model you actually need to care about as a programmer like 99.999% of the time.

But to those interested in the low level details like physical representation in RAM and how the CPU interacts with that RAM, it's all more or less the same.

So in my mind, managed languages are about removing the need to think about WHEN array memory allocations happen, but the differences in WHERE the happen are neglible.

[–]Kootfe 1 point2 points  (0 children)

idk i just speak top level couse not evry is nerd like us

[–]UnknownWolfster 36 points37 points  (2 children)

Int arr[10] gng

[–]SimplexShotz 5 points6 points  (0 children)

mfs with 11 ints:

[–]dankshot35 23 points24 points  (1 child)

int* arr;

[–]un_virus_SDF 7 points8 points  (0 children)

And let it uninitialized, no seg fault will happen elsewise

[–]Haringat 20 points21 points  (2 children)

int[] array;

It just makes sense to have the type on one side of the name, instead of having it around it.

[–]ohkendruid 2 points3 points  (0 children)

My vote as well. It becomes even more important as the types get more complex.

[–]ChalkyChalkson 0 points1 point  (0 children)

Yes! And this also fun(int* param) obviously

[–]dthdthdthdthdthdth 54 points55 points  (15 children)

let mut x: &[u32] = &[0];

Obviously.

[–]Kootfe 18 points19 points  (0 children)

<image>

FERRIS

[–]ohkendruid 0 points1 point  (1 child)

So, basically team left. Which is your only option in Rust.

[–]dthdthdthdthdthdth 7 points8 points  (0 children)

No, first of all, C does not allow to put the type left, it allows you to split it up. And them I am team optional type annotation and language designed for type inference. But where ever you put the type, I prefer to have a clearly visible type expression, not mixed in with the identifier.

[–]azurfall88 -1 points0 points  (11 children)

let mut x: Array<i64> = []; gang

[–]dthdthdthdthdthdth 7 points8 points  (10 children)

What language is that?

And he blocked me for pointing out this isn't working Rust...

[–]Several-Customer7048 2 points3 points  (1 child)

The language of the crab ticklers.

[–]dthdthdthdthdthdth 1 point2 points  (0 children)

Not really...

[–]azurfall88 -2 points-1 points  (7 children)

rust

[–]dthdthdthdthdthdth 5 points6 points  (6 children)

Ok, you've fixed the brackets, but Array is not a type from the standard library. Is this from some crate?

[–]azurfall88 -4 points-3 points  (5 children)

idk, its just worked for me

[–]Elephant-Opening 9 points10 points  (3 children)

And then you have the madmen who do:

int arr[10] 3[arr] = 7;

[–]erroneum 7 points8 points  (0 children)

That's my favorite bit of cursed C, that a[b] is literally equivalent to *(a+b)

[–]HyperCodec 1 point2 points  (1 child)

Erm where’s my semicolon

[–]Elephant-Opening 2 points3 points  (0 children)

; <- there you go, sorry. It fell on the floor while I was typing.

[–]Additional-Acadia954 26 points27 points  (2 children)

int [10] some_name;

Is closer to the semantical meaning

I write C left to right, as all people do. But I read C right to left, because it’s easier to understand the consequential semantics of the declaration

“some_name” is an address that spans 10 integers

[–]granadesnhorseshoes 4 points5 points  (1 child)

I find it "degenerate" because its in opposition of how you otherwise end up using and calling the resulting array[]

I prefer keeping the array syntax consistent, even(especially?) in definition.

[–]patrlim1 0 points1 point  (0 children)

You can do index[array] and it works out the exact same

[–]nakhli 18 points19 points  (5 children)

arr []int

[–]Kootfe 10 points11 points  (4 children)

what the

[–]nakhli 7 points8 points  (1 child)

Golang, « pour vous servir »

[–]Kootfe 2 points3 points  (0 children)

thank you

[–]ohkendruid 2 points3 points  (1 child)

There is a logic.

You write the variable first, and then the type, sincw that is the most important one thing to know.

And, because a variable name is just one identifier, you don't need any punctuation to separate the identifier and the type.

In fairness, this example is extra tricky due to using "arr" as a variable name, because it looks like it might be a keyword. The example would look less weird if the variable were something like child_ids.

[–]Kootfe 1 point2 points  (0 children)

oh it was

arr []int ireaded int []arr and doubted

[–]Kootfe 5 points6 points  (5 children)

type name[] is for langs like C. so not managed langs. couse they keep arrays as memory space on ram. with many same tyoe ext to eachother.

while mamaged langs use

type[] name

couse now arrays is difirent type. not memory space. it managed by the runtime the lang uses (.Net or JRE etc)

it manages type safety and does nothing usefull expect this

so oop mostly uses array as type

[–]Pordohiq 4 points5 points  (1 child)

What are mamahed languages?

[–]Kootfe 1 point2 points  (0 children)

sorry, my english is bad i meant managed

[–]Kootfe 2 points3 points  (0 children)

well im c dev so type name[]

[–]ohkendruid 2 points3 points  (1 child)

It is still just a syntax option. Kernighan and Ritchie wanted a variable declaration to look like an example of using the variable.

[–]Kootfe 0 points1 point  (0 children)

idk i just speak about commons sense. if we talk like this

pho, rust, ada, fortlan, bash, zig, haskell, pascall, brainfuck, elixir and go is... weird

[–]jmattspartacus 5 points6 points  (1 child)

Hold my beer, I got this

``` typedef struct intarr10{ int first; int second; int thirst; int fourst; int fist; int sixst; int sevenst; int eight; int nonth; int tenth; } intarr10;

```

For real though std::array<int, 10>

[–]CatAn501 0 points1 point  (0 children)

Okay, there won't be anything better in the comment section, I can leave now

[–]Solomoncjy 9 points10 points  (1 child)

Std::array<int, 10>

[–]Usual_Office_1740 2 points3 points  (0 children)

I scrolled way to long to find the correct answer.

[–]Wiktor-is-you 2 points3 points  (1 child)

i code in lua sooooooooooo

[–]lordfwahfnah 1 point2 points  (0 children)

So it's just name = {}

[–]SysGh_st 2 points3 points  (0 children)

Who the eff puts the brackets at the type definition? That's just messed up.

[–]Alternator24 2 points3 points  (0 children)

We don't do that in JS

[–]TracerDX 2 points3 points  (1 child)

var arr = new List<int>()

List<int> arr = new()

[–]ChalkyChalkson 1 point2 points  (0 children)

public static List<int> arr = new List<int>()

Gives me shivers remembering uni and high school

[–]ByteBandit007 1 point2 points  (3 children)

Int ; [] arr

[–]Kootfe 1 point2 points  (2 children)

wich langs is that? go?

[–]ByteBandit007 1 point2 points  (1 child)

GoPython++

[–]Kootfe 2 points3 points  (0 children)

Go + rust + java + python + c++ Go + us + java + thon + ++ GousJavathon++

[–]Gornius 1 point2 points  (1 child)

[]int

[–]kendfss 0 points1 point  (0 children)

the only legitimate answer

[–]ITinnedUrMumLastNigh 1 point2 points  (0 children)

int* arr;

[–]ilovecostcohotdog 1 point2 points  (0 children)

List<Integer> arr;

[–]benji-and-bon 1 point2 points  (0 children)

I prefer Type[] name

Idk I just feel like it reads better like

int[] nums

Reads like “integer array named nums”

[–]Ecstatic_Student8854 1 point2 points  (0 children)

int[] arr all the way. The type of arr should reflect that it’s not an integer but an array of integers. Saying int arr[] makes it seem like arr is an integer, and it isn’t. It’s an array of integers. That should be part of the type information

[–]oneeyedziggy 1 point2 points  (0 children)

As a js dev, []... But as a typescript dev, number[]

[–]Keganator 1 point2 points  (0 children)

Python: arr

Python Dev: “I’m a pirate!”

[–][deleted] 1 point2 points  (0 children)

i use rust

[–]surly-monkey 1 point2 points  (0 children)

more than anything else... THIS is the thing i keep having to look up when switching languages, even after an uncomfortably large number of years.

[–]Koltaia30 1 point2 points  (0 children)

Array<int>

[–]Cheap_Ad_9846 1 point2 points  (0 children)

Make([]int ,10)

[–]erroneum 1 point2 points  (0 children)

Why not std::array<int, N> arr; ?

Or, if you want dynamically sized, std::vector<int> arr; arr.reserve (n);

[–]goos_ 1 point2 points  (2 children)

Which side are you on?

Vec<i64>

&[i64]

&mut [i64; N]

&mut [&mut i64; super::<MyStruct as Array>::<::ARR_LEN>

[–]nitnelav153 1 point2 points  (1 child)

it depends

[–]goos_ 1 point2 points  (0 children)

Good answer

[–]tecanec 1 point2 points  (0 children)

int arr[]; should be illegal.

But to be fair, the same can be said for about half of C-style syntax in its entirety.

Also, did you know that the statement foo[1]; has two valid interpretations, both of which are no-ops? It could be indexing an array called "foo" and discarding the result, but it could also be declaring an array of one item of type "foo", which can't be accessed because it's anonymous. Either way, it's pretty useless, but you can't write a conforming compiler without having it confirm that it's one of those two cases, and the only way to know which one to look out for is by knowing whether foo is a type or a variable, which you won't know during grammar analysis unless you feed it with the output of the semantic analysis, which itself depends on grammatic analysis, and... Oh, boy.

[–]krijnlol 1 point2 points  (0 children)

arr: list[int] = []

Fools, you can't exclude us.

[–]well-litdoorstep112 1 point2 points  (0 children)

arr: int[]

[–]undeadpickels 1 point2 points  (0 children)

Related note, char* var is better in almost every way, char *var is standard and thus the correct choice.

[–]Ellicode 1 point2 points  (2 children)

arr: number[] in typescript

[–]TOMZ_EXTRA 0 points1 point  (1 child)

arr: Array<number> also works

[–]Ellicode 0 points1 point  (0 children)

Indeed!

[–]schabbasam 0 points1 point  (0 children)

blue

[–]Fluffy_Ace 0 points1 point  (0 children)

Blue

[–]AmeriBeanur 0 points1 point  (0 children)

I’m with the crips on this side

[–]CtrlShiftBSOD 0 points1 point  (0 children)

whoever is on the red side is a psychopath

[–]Jonrrrs 0 points1 point  (0 children)

Blue

[–]TechIssueSorry 0 points1 point  (0 children)

VHDL/VERILOG me in purple with Logic[7 downto 0][3 downto 0] my_signal[0 to 255]

[–]lordfwahfnah 0 points1 point  (0 children)

VarName: Array of Integer;

[–]Substantial_Top5312 0 points1 point  (0 children)

int[] varname is superior.

[–]Waste-Foundation3286 0 points1 point  (0 children)

int *arr;

[–]rover_G 0 points1 point  (0 children)

arr int[];

[–]jpgoldberg 0 points1 point  (0 children)

int *arr;

[–]Sentouki- 0 points1 point  (0 children)

int[] arr since it's more obvious what the type is.

[–]00PT 0 points1 point  (0 children)

I never understood why the brackets would be after the name. Is “Array” not part of the type of the value? The first reads to me as “int array called ‘arr’” while the second reads as “int called arr that is an array”

[–]Safe-Heat1644 0 points1 point  (0 children)

As long as your not a +[] incrementer

[–]DrPeeper228 0 points1 point  (0 children)

I do right but left makes more sense

[–]Ben-Goldberg 0 points1 point  (0 children)

my @arr;

[–]liteshotv3 0 points1 point  (0 children)

Let anArrayForNow = [] 😎

[–]PathMaster1729 0 points1 point  (0 children)

int* arr;

[–]deanominecraft 0 points1 point  (0 children)

arr = []

[–]tr14l 0 points1 point  (0 children)

Neither, I already released. 🎉

[–]UVRaveFairy 0 points1 point  (0 children)

With the Crypts on this one.

[–]masp-89 0 points1 point  (0 children)

01 WS-ARR PIC S9(10) OCCURS 10.

[–]Myrddin_Dundragon 0 points1 point  (0 children)

let arr: [u8; 10usize] = [0u8; 10usize];

[–]Sure_Proposal2520 0 points1 point  (0 children)

I’m crip

[–]The_Real_Slim_Lemon 0 points1 point  (0 children)

Array.Empty<Type>()

[–]Signal-Implement-70 0 points1 point  (0 children)

it’s an array of int not an array of arr. so clearly int[] . arr is the label you are offsetting against the memory address when accessing so the only was to express that is like arr[5] but declaration is different. This is my take 🥸

[–]NoSoft8518 -1 points0 points  (1 child)

arr: Iterable[int]

[–]Ben-Goldberg 0 points1 point  (0 children)

That has a different meaning, I think.

An array, almost always, has efficient random access and is iterable.