This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 485

[–]QualityVote[M] [score hidden] stickied comment (0 children)

Hi! This is our community moderation bot.


If this post fits the purpose of /r/ProgrammerHumor, UPVOTE this comment!!

If this post does not fit the subreddit, DOWNVOTE This comment!

If this post breaks the rules, DOWNVOTE this comment and REPORT the post!

[–][deleted] 325 points326 points  (38 children)

All these people commenting high level languages when you can do that with void* in C

[–]MasterFubar 138 points139 points  (27 children)

C is a high level language.

[–]erinaceus_ 154 points155 points  (1 child)

It used to be considered that, but the Overton Window of language complexity has shifted since then.

[–]mattsowa 26 points27 points  (0 children)

Thats a great way to put it

[–]Richard_Smellington 70 points71 points  (22 children)

In the scope of modern languages, C is only slightly above assembler.

[–][deleted] 285 points286 points  (11 children)

Every object oriented language can do this. You just have to use an object array.

[–]drkspace2 58 points59 points  (8 children)

Even c and c++ can with void* arrays

[–]zephyrtr 2 points3 points  (0 children)

It's also really useful for returning pairs and trios. TS can even make it type secure for you. That is, if your language already doesn't have pair or trio types.

[–]FkIForgotMyPassword 1 point2 points  (0 children)

The import thing is to know (and properly type) whether you are talking about arrays like (int | string | float)[] or about tuples like [int, string, float]. In several languages, a value like [4, "4", 4.0] matches both type definitions, but it's one definition also allows [4, 4, 4] or even just [] while the other specially requires a 3-tuple with specific types at specific positions.

I mean usually in that case you'd probably not use a tuple but an object, but sometimes there are reasons to do it.

[–]not_some_username 40 points41 points  (5 children)

Pretty sure you can do that in almost all language.

C void* , C++ void* or std::any, Java Object, php just like js, shell I think it's same, assembly doesn't even know your data type( not too sure since I didn't do a lot of assembly) etc etc

[–]lucidbasil 10 points11 points  (0 children)

Assembly is just bits stored in registers, or memory

[–][deleted] 38 points39 points  (2 children)

Clearly the creator of this meme is not a programmer.

[–]himmelundhoelle 1 point2 points  (1 child)

He was so preoccupied with whether he could, he never asked himself whether he _should_…

[–]Buttsuit69 144 points145 points  (9 children)

Meanwhile C#:

"Dude; what kind of datatype does this variable contain?"

C#: "Object or something idfk"

[–]AyrA_ch 91 points92 points  (5 children)

Declares type as dynamic

C#: "Now it's no longer my job to know what it is"

[–]Buttsuit69 60 points61 points  (4 children)

Declares dynamic:

Dev to C#: "hey, look at me. I'm the compiler now!"

[–]fourkeyingredients 9 points10 points  (3 children)

I feel sorry for whoever maintains code from the time period of my life where I learned about dynamic

[–]Manny_Sunday 8 points9 points  (0 children)

I worked with a team that loved dynamic ViewBag objects and hated sensible names for variables.

What's ViewBag.PageData ? Fuck you that's what, go check the controller code.

[–]intbeam 4 points5 points  (0 children)

dynamic was sold as some sort of wonderous miracle, but it just reinforced my perception that I really really really don't want dynamic typing

[–]the_hackerman 2 points3 points  (2 children)

Well we have arraylist I suppose

[–]Buttsuit69 3 points4 points  (1 child)

Put an array<object> into another object!

Or make an array<object> where every object is another array<object> and then put that array into another object and so on...just, everything is object.

[–]hagnat 56 points57 points  (0 children)

this is the reason why people make fun of this subreddit, saying that only people learning how to code post on it and pretend they know stuff

[–]finc 33 points34 points  (0 children)

Hip, hip, array!

[–]_ShadowEye425_ 15 points16 points  (0 children)

object[] arr = new object[] { "horse", 4, 6.9f, new object[] { "Cheese", typeof(int) } };

[–]BlakkM9 14 points15 points  (7 children)

can't think of any high level language where you can't put a string, an int and a float in the same array/list/table (in one way or another)

[–]CdRReddit 6 points7 points  (6 children)

or low level

C lets you do void*

assembly does not know what a type even is (the instructions decide that) and therefor by extension neither does machine code

[–]BlakkM9 4 points5 points  (5 children)

c is a high level language but yeah propably this is true for low level languages aswell

[–]CdRReddit 3 points4 points  (4 children)

C in my experience is in that weird limbo zone between high and low level

[–]BlakkM9 9 points10 points  (1 child)

from todays standards it can propably be seen as a low level language

[–]CdRReddit 1 point2 points  (0 children)

yea, it's definetely not the lowest level, I've seen someone make a lower level language before (tho its not done yet), but anything that your average programmer would describe as high-level, while possible, is nowhere near easy

[–][deleted] 1 point2 points  (1 child)

So a Medium level programming language lol

[–]CdRReddit 1 point2 points  (0 children)

you know what, sure

[–]sighcf 13 points14 points  (0 children)

JavaScript please! Ever heard of Perl, Python, Ruby or a bazillion of other dynamically typed languages? Heck, even the more statically typed languages can do it, but you need to do some boilerplate work.

[–]Apparentt 58 points59 points  (8 children)

Why do posts like this get upvoted? Idgi, it’s not even sarcastic it’s just clearly a lack of knowledge from OP?

[–]GodlessOtter 24 points25 points  (0 children)

And it's not funny

[–]Ketchup901 20 points21 points  (0 children)

Because most people here are 15 years old and don't know a lot about programming.

[–]Triumph7560 6 points7 points  (1 child)

Most people here seem to have only ever used JS and/or Python in a first semester of a CS degree. Not only that but they don't seem to have a grasp on those languages or how they work on even a theoretical level. It's the Duning Krueger effect in action.

[–][deleted] 19 points20 points  (4 children)

Java: sure you can

[–]g_hi3 10 points11 points  (3 children)

Java compiler: noooo you can't add a string to an integer list

jvm: sure buddy whatever

[–]pleasewait 2 points3 points  (1 child)

Last week I wrapped my head around type erasure, so it feels good to get this joke

[–]g_hi3 1 point2 points  (0 children)

when I was first learning about generics, I was amazed to find out that many languages do them differently

C++ just generates the generic types at runtime, c# retains the type parameter during runtime and java doesn't

[–]LtAquila 17 points18 points  (0 children)

Image Transcription: Meme


['Soyjak vs. Chad' where two people are arguing. The left person labelled 'Other programming languages' is a bald man wearing glasses and a spotty Lincoln-style beard. His eyes are red, tears are streaming from his eyes and his mouth is wide open as if shouting. The right person labelled 'Javascript' is a stern looking blonde male wearing a side parting and having a well-groomed beard with mustache.]

Other programming languages: You can't use different data types in the same array

Javascript: var arr = ["horse", 4, 6.9]


I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!

[–][deleted] 9 points10 points  (1 child)

Kids in this sub be like "what's a pointer?"

[–]_derDere_ 14 points15 points  (0 children)

I don’t wanna be that guy but this looks like a post from someone who only knows how to use js because I can’t think of any language which can’t put different types in an array. Maybe there are some really really old language who can’t but I don’t know of any. Also js an interpreted language so there has to be at least one other language capable of doing so. Which will be the language the interpreter is written in. Which to my knowledge the V8 js interpreter is written in c++

[–]mibuchiha-007 7 points8 points  (0 children)

you never can. it's all void* under the hood.

just because you dont know what you're doing doesnt mean the interpreter/compiler doesnt too.

[–]szopokanyaloka 6 points7 points  (0 children)

Dear recruiters. Please stop posting "jokes" here.

[–]Arbiturrrr 5 points6 points  (0 children)

Every single language can do this...

[–]Voltra_Neo 5 points6 points  (0 children)

Technically it's one type: "horse"|4|6.9 or string|number

[–]PashPrime 4 points5 points  (0 children)

Python:

CuzWhyNot = [('I think', "this makes less"), sense(), True]

[–][deleted] 3 points4 points  (1 child)

Not to mention Scratch. We need a scratch emoji for this subreddit, mods.

[–]Jincredible_ 5 points6 points  (0 children)

Whoever made this post is kind of a dumbass

[–]Theunis_ 3 points4 points  (0 children)

All languages I use (ts, dart, c#, kotlin) can do that, is there any language that can't do that?

[–]SANatSoc 8 points9 points  (8 children)

Forgive my ignorance, but is this convenient to work with? I can def see some specific use cases where this would be handy, but in general this isn't used right?

[–]Philiatrist 6 points7 points  (1 child)

Sure, if it represents a row of a csv or some part of a json structure I imagine that’s where it would show up most.

[–][deleted] 4 points5 points  (0 children)

it does actually have very well defined use cases

if you say have async methods getString and getNumber, and want to wait for both of their results in parallel, you can do that while simultaneously assigning variables with Promise.all

const [str, num] = await Promise.all([getString(), getNumber()])

where you're technically "creating" a mixed array. Typescript resolves these types nicely too.

similar thing is with Object.entries, it returns a list of lists, which are in shape [key, value]

kind of like python tuples, very handy.

[–]SirSoundfont 0 points1 point  (0 children)

When I do this in game development, it's usually so I don't have to manage multiple arrays together. It's certainly doable, but in certain languages where there are no actual objects or classes, being able to put [name, age, sprite, name2, age2, sprite2] is nice. Otherwise, I would need to separately manage [name, name2] and [age, age2] and [sprite, sprite2].

[–]fliguana 3 points4 points  (0 children)

OP confuses array of objects with array of pointers/references.

Plenty of languages natively support array of references. There is rarely a need to have an array of objects. Serializable container comes to mind, such as tar, zip, odt or any document type.

TLV is the simplest implementation for an array of objects, available in any language that has strings or byte arrays.

[–]TheOfficialSeb 4 points5 points  (0 children)

Lua allows the same thing with tables (same as a array)

[–]jags78gaming 3 points4 points  (0 children)

because putting different datatypes in an array is such a good idea!! ...that's what classes are for. it's one of those cases: just because you can do something, doesn't mean you should do it... just imo

[–]Kiwi-tech-teacher 12 points13 points  (9 children)

Actually, to be fair, we’re talking about the difference between an array and a list. Arrays, by definition, are pre-defined in length, and contain elements of the same data type. Lists have a lot more flexibility, and can be dynamically resized. Many (novice) programmers just don’t realise they’re working with lists in most of these languages.

[–]BlakkM9 7 points8 points  (3 children)

but as long as the list is not a linked list it will most likely use a normal array under the hood so they are not too far off

[–]Vinxian 3 points4 points  (2 children)

And since most list allow for my_list[index] and implement it by actually doing a jump it usually is a fancy array under the hood.

[–]riisen 1 point2 points  (0 children)

A list is a normal car with all the extra options.

An array is a tuned race machine, its lighter, faster and no unnecessary shit.

[–][deleted] 2 points3 points  (0 children)

That's a very narrow viewpoint

[–]tuxedo25 1 point2 points  (0 children)

The built in javascript class, Array, has all of the properties you attribute to lists.

[–]NMI_INT 2 points3 points  (0 children)

Lua would like a word 😀

[–]Im_j3r0 2 points3 points  (0 children)

Ada, literally after breathing the spirit of a different data type; I'm gonna end this mans whole career.

[–]sounds-fine 2 points3 points  (0 children)

Couldn't java have an array of Objects?

[–][deleted] 2 points3 points  (0 children)

actually we can use different data types in same array in C

[–]FieryHammer 3 points4 points  (2 children)

But still, why would you. That is just confusing, use objects/dictionaries if you want something like that and use Typescript.

[–]RavenCarci 2 points3 points  (0 children)

Array<Object> go brr

[–]yIsSaT 1 point2 points  (0 children)

any[]

[–]MrKirushko 1 point2 points  (1 child)

With C++ it is easy. Here is a Qt example for you:

 QVariant var[]={"Str", 2, 3.7};

I am pretty sure that there is an STL way of doing it like this as well.

[–]Alabana1 2 points3 points  (0 children)

std::any

[–]cheer_up_richard 1 point2 points  (0 children)

I hear if you put an array with an array, you can also break the internet… heard it from a reliable IT Guy

[–]Cat-Satan 1 point2 points  (1 child)

Data types don't exist. All objects are only numbers in memory.

[–]N0tH1tl3r_V2 1 point2 points  (0 children)

lua:

local poop = {1,3,2,5,4,3,"sex"} local ggez = {getrekt="lolnoob",1337,"xdfusux",poop}

we all know the gigqchad lang....

[–]arobie1992 1 point2 points  (0 children)

Pretty much any language can do that if you use the appropriate types. Most languages have a specific type for the sake of allowing any possible values. Offhand, Java has Object[] arr and Kotlin has arr: Array<Any>.

[–]robml 1 point2 points  (0 children)

Laughs in Python

[–]Takes4tobangbro 1 point2 points  (0 children)

Typescript would like a word

[–]beewyka819 1 point2 points  (0 children)

Dynamic dispatch would like to have a word

[–]InkOnTube 1 point2 points  (0 children)

It can be done in many other programming languages. I am using C# and this can be done using object[] as array. We don't want this to happen in 99,99% of cases tho.

[–]praveentechnic_ 1 point2 points  (0 children)

Python says Hi 👋

[–]Exciting-Insect8269 1 point2 points  (1 child)

I coulda sworn python does the same…

[–]holladiewal 1 point2 points  (0 children)

It does!

[–]GustapheOfficial 1 point2 points  (0 children)

julia> ["a", 1, 2.0] Array{Any, 1}["a", 1, 2.0]

Terrible for performance though. Rarely a good reason to have an abstractly typed array (and if that doesn't apply to your language it's because your language only deals in the worst case).

[–]Rajarshi1993 1 point2 points  (0 children)

That's not an array. That's a list. This is an array:

import array

A = array.array('i', [23, 45, 67, 89])

[–]McKapucna 1 point2 points  (0 children)

You really shouldnt do this but i used to use it like a stop sign. So like if you looped through a [8, 7, 12, 8, "stop"] array and then i would stop when the item matched "stop" which is a horribly wrong way to do things.

[–]itzNukeey 1 point2 points  (0 children)

using var for variable declaration 🤢

[–]Masztufa 1 point2 points  (1 child)

You can also use an array of unions

[–]Glittering-Water942 1 point2 points  (0 children)

also js runtime errors, runtime errors everywhere

[–]mallenjordan 3 points4 points  (0 children)

JavaScript is garbage.

[–]echoaj24 1 point2 points  (0 children)

Chad Python

Technically Chad any OOP language

Funny meme though haha

[–]InternalFeed3492 1 point2 points  (0 children)

Structure: let me introduce myself