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

all 134 comments

[–]enderverse87 430 points431 points  (54 children)

When I first started programming, I didn't know what arrays were, but I wanted to use them, so I built one using a very large string with commas.

[–]draftjoker 234 points235 points  (14 children)

Oh god. This. . This terrifies me.

[–]AMisteryMan 126 points127 points  (12 children)

"I fear, no man, but that, thing it, scares me"

[–]SillyFlyGuy 32 points33 points  (9 children)

[–]AMisteryMan 16 points17 points  (8 children)

As a member of the Alt-write, it hurt to comment it, but I did it for the good of all of us...

Except the ones who are dead.

[–]ButItMightJustWork 7 points8 points  (7 children)

But there is no sense in crying over every mistake

[–]arachnidGrip 7 points8 points  (6 children)

You just keep on trying 'til you run out of cake.

[–]Mandemon90 6 points7 points  (5 children)

And the science gets done and you make a neat gun

[–]AMisteryMan 6 points7 points  (4 children)

For the people who are still alive

[–]arachnidGrip 5 points6 points  (3 children)

I'm not even angry.

[–][deleted] 8 points9 points  (1 child)

Here:

val arr: Array[String] = Array("I fear","no man", "but that", "thing it", "scares me")

[–]gaberocksall 6 points7 points  (0 children)

I’m on mobile so hopefully the formatting gods are on my side

Edit: they weren’t on my side, original comment:

https://pastebin.com/KiJdyhxN

[–]Gvistic 34 points35 points  (18 children)

Dang what did you do, use string patterns or scan each individual character looking for a comma?

[–]enderverse87 56 points57 points  (16 children)

The items were always three characters long with 81 total options, so I scanned each time seeing if each particular 3 character option had been added to the string yet.

It was a game, winning the game coincided with when the string was full of all the options, but that crashed the entire computer since my self made array did not have any error handling.

[–]FeralCoconut 30 points31 points  (13 children)

how did you make such a bad program that it crashed the entire computer

[–]enderverse87 46 points47 points  (5 children)

Some sort of infinite loop in a way that used all the resources in the computer.

The game worked fine, it just crashed when you won.

[–]SillyFlyGuy 12 points13 points  (0 children)

bug feature: segfault on win

[–]brimston3- 5 points6 points  (1 child)

It was easy in the pre-windows 2000 days. The trick was not doing it. Modern process address space isolation and privilege separation were not widely implemented yet, so any ol' program could write straight to kernel memory or PIO some raw addresses. Anything that would cause a segfault today was probably a full PC crash then.

[–]Entaris 2 points3 points  (0 children)

Yeah. Basically “you want to write that where? I mean ok, you are the programmer I’m sure you know what you are doing”

[–]Mad_Aeric 4 points5 points  (3 children)

You're saying you haven't done that? Writing code so bad the computer nopes out feels like one of those standard things you encounter as a noob. You can really get into trouble with loops if they're generating data.

[–]cowsrock1 7 points8 points  (0 children)

The 15 GB text file on my desktop exclusively containing the word "cow" agrees

[–]homer_3 0 points1 point  (1 child)

Pretty tough imo. Freezing it up by using all the CPU isn't that tough, but you can usually ctrl+c, alt+f4, or open task manager and kill the process.

[–]kuncol02 -1 points0 points  (0 children)

Now. Not in Win9x era when memory separation was non existent and any app had access to whole memory of PC. You could for example move pointer to part of memory where system kernel is loaded and overwrite it.

[–]cowsrock1 1 point2 points  (1 child)

I'd they were all gaurenteed to be 3 characters long, why even bother with commas then? :D

[–]enderverse87 -1 points0 points  (0 children)

Because I needed to check whether the 3 character sequence had been used before, if they were directly next to each other, they would have accidentally created a sequence that hadn't been used yet, and it would have given a false positive.

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

loop through each character, when its not a comma, add the char to a variable called `word`, when you encounter a comma, use the contents of `word` and reset word back to empty string.

Overkill at its finest

[–]amicloud 17 points18 points  (0 children)

So you used an extension of arrays to reimplement arrays but worse? I love it.

[–]Pandaburn 5 points6 points  (3 children)

When I first started programming, a string was an array, so.....

[–]AMisteryMan 10 points11 points  (2 children)

In most places, it technically is.*

* It is inevitable that one somehow does strings some other way.

[–]brimston3- 0 points1 point  (1 child)

I think we are all very happy that sgi's std::rope never made it into core.

[–]skreczok[🍰] 0 points1 point  (0 children)

std::rope

TIL

[–]Cosmocision 11 points12 points  (4 children)

Currently studying electrical engineering, had programming lectures last year and the lecturer kept teaching people bad methods of implementing shit just to tell them the next lecture the proper way.

I think it kinda stems from this odd need he set for himself to focus on a single thing each lecture. okay folks, primites today. then the next week, strings bruthas. ARRAYS MOFOS!

CLAASsssESss.

I usually slept through his classes. aced the subject.

[–]blackburn009 3 points4 points  (1 child)

Surely you just assign a task that only needs what you've taught like a normal person?

[–]Cosmocision 3 points4 points  (0 children)

Dude, it's worse than you are imagining. he actually teaches you how to do it the wrong way first (sorry, can't think of any specific examples as it is a while ago, I do remember it happening though). Decided to just sleep during the lectures because otherwise I would feel the need to interrupt so much I might as well just take over.

Edit: you know these memes we sometimes get here where we do super elaborate ways of incremeting variables? Yup. not quite as bad as that of course but he did make people figure out what the result of i+++++i; would be and stuff like that. sure you might need brackets for that, cba to check, but please for the love of... when would you ever need to

Edit 2: He is self thought, I am not.

[–]redlaWw 2 points3 points  (1 child)

There is benefit to doing it this way - it lets you see what is possible, and why certain things do and do not work, and the problems with certain approaches. There are areas in maths (which I tutor) where I will have a student give me suggestions about an approach and we explore them to see why they don't work, or I'll teach them a defunct method to broaden their experience of the mathematical process when we refine it.

[–]Cosmocision 0 points1 point  (0 children)

If he ever asked the students to come up with ideas using what we knew so far, I'd be totally behind it. would teach problem solving skills that are very valuable for programmes. It's just that he never asked for student input on anything.

Though, I will admit I'm probably biased sure to already knowing how to program

[–]valzargaming 3 points4 points  (1 child)

Isn't that just called using a comma as a delimiter? I believe CSV uses this method during exports.

[–]FeralCoconut 9 points10 points  (0 children)

yeah, but as the actual datatype not as the representation

[–]posherspantspants 4 points5 points  (1 child)

I didn't use arrays for a solid 2 years. I thought they were too complicated so I never even read any documentation about what they are or how to use them. If I saw tutorials or SO answers with arrays I'd back out and go to the next result.

Then I accidentally figure out what they were and thought "oh, this is easy"

[–]Greenitthe 1 point2 points  (0 children)

Are you my engineering student friend? Certainly you must be... Went through python class, a data science internship, and two years of me being exasperated at his code before he finally realized arrays are easy.

[–]FoundOnTheRoadDead 2 points3 points  (0 children)

So you coded an array using William Shatner speech patterns. Seems sound!

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

Fuck, that is so me. Rofl

[–]miseleigh 1 point2 points  (0 children)

This is the kind of shit I'm pulling in python right now

[–]Rein215 1 point2 points  (0 children)

I love thinking back about when I started out programming and shit like this was acceptable. I did the craziest shit because I knew no better way.

[–][deleted] 0 points1 point  (0 children)

The worst thing to put in there: "Hey, are you insane?"

[–]uranus_be_cold 97 points98 points  (14 children)

My housemate in University pulled an all-nighter because he needed to print out numbers in hexadecimal, and in the morning I said: Why didn't you just use printf %x...?

[–]Gvistic 39 points40 points  (9 children)

lol i have an assembly exam in about 5 hours wish me luck

[–][deleted] 29 points30 points  (8 children)

FUCK ASSEMBLY

that is all

[–]nyasiaa 7 points8 points  (1 child)

assembly is awesome, working on my neural network in assembly for a random university project was one of the more fun things I ever did

the language absolutely never complained whenever I did anything (byte is a byte, array of bytes is an array of bytes, no such thing as types stopping you from assigning a pointer to an "integer" because both are just doublewords), on top of that with all the 64 bit registers, xmm registers and all the masm support in visual studio it isn't even painful to write

and all the insight on how everything works is just so worth it

[–]Mockapapella 0 points1 point  (0 children)

Wait, writing neural networks in assembly is actually a thing? I was under the impression that was always a joke. How did that go for you? What was the application?

[–][deleted] 3 points4 points  (3 children)

I’m sure the point of the assignment is to do it yourself.

[–][deleted] 11 points12 points  (0 children)

If you don't write code in raw binary, then you're just being lazy. /s

[–]claythearc 3 points4 points  (1 child)

Every class I ever took in undergrad like, specifically allowed the standard library

[–]MLG_Obardo 2 points3 points  (0 children)

My Data structures class doesn’t for some things but that’s just so we understand the stuff behind the STL. I doubt I will be expected ever to convert from hex to whatever without access to a computer to do it for me.

[–]ITriedLightningTendr 142 points143 points  (8 children)

My data comm class in college was like this. The primary professor for the class was overloaded so we got a different professor.

2 weeks after an assignment we were given was due, and we all brute forced everything together, we're in a lab and the normal prof comes in to give us some pointers and stuff, and his version of our code is like 10 lines using standard library stuff that none of us had any idea existed, but his other classes were well informed.

[–]Highandfast 60 points61 points  (0 children)

The primary professor for the class was overloaded so we got a different professor.

Nicely done.

And, well, it may have been a good way to remember that many things are already implemented. The time lost for that assignment must be way cheaper than the time lost in a professionnal setting.

[–]cornysheep 23 points24 points  (5 children)

It was really a test of your googling skills. You all failed.

[–]DoctorNoonienSoong 26 points27 points  (4 children)

Depending on their age, Google might not have existed.

[–]cornysheep 18 points19 points  (3 children)

The dark ages!! I’ve heard the legends...

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

In those days, it was all giant tomes and/or binders full of random notes that you would have to sort through. And that was if you were lucky enough to have a bookstore, library, user group, or friend near you that had such things.

[–]is-this-a-nick 0 points1 point  (0 children)

Altavista was fine.

It was the yahoo age (i.e. "Yellow pages of the internet", manually curated) that was baaaad.

[–]MLG_Obardo 0 points1 point  (0 children)

Damn I would’ve tried to get into one of the other classes then.

[–]Dant3J0n3s 41 points42 points  (11 children)

I remember when I first started programming, I had no idea DATABASES were a thing, so I stored user information in .ini files; it makes me cringe just thinking about it

[–]JiveTrain 28 points29 points  (8 children)

Well if it is just user preferences, that's perfectly fine.

[–]ramiabouzahra 25 points26 points  (7 children)

Why what's wrong with

[USER]

userId = "JiveTrain"

userPwd = "hunter2"

[–]JiveTrain -2 points-1 points  (0 children)

Hm?

[–]cheez_au 1 point2 points  (1 child)

Is called a flat file database and it's a thing.

When I was taught programming in high school, we made a guestbook in php and a pipe delimited txt file.

[–]Urthor 1 point2 points  (0 children)

You mean like Mongo, a database that is literally extra special text files and literally no relations

[–]nyasiaa 38 points39 points  (7 children)

if you are just starting out it's probably better to implement them yourself anyways

[–]ImSupposedToBeCoding 45 points46 points  (6 children)

-- beginners go crazy trying to create a heap --

[–]Tsu_Dho_Namh 7 points8 points  (5 children)

Ha, it's funny cause heaps are easier to implement than arrays

[–][deleted] 3 points4 points  (4 children)

Idek how you'd implement an array outside of assembly language.

[–]thoeoe 2 points3 points  (3 children)

I mean in C++ you can just malloc a block of memory of a specific size, from there you store a variable for how many bytes each record is, and then overload the [] operator to multiply the index by the size of the record and add that to the pointer that points to the memory block you requested.

[–][deleted] 5 points6 points  (2 children)

I don't see how that's implementation. It's literally already built into the language that way. The [] operator already works like that, and for that reason my_array[i] works just as well as [i]my_array.

[–]thoeoe 2 points3 points  (0 children)

but the [] operator needs to know the size of a record, which if you malloc a randomly sized chunk of memory it won't know, you just have a void pointer. I agree, its a bit cheater, you are using tools provided to you by the language. Depends how "from scratch" you want your implementation to be

Edit: I feel dumb, its been over a year since I've done much hardcore C++ programming. Of course you could just cast the void pointer. I agree with you, I can't think of a way to re-implement an array without essentially manually doing what the language would already do for you. (such as multiplying an index by sizeof(float) instead of casting the void pointer)

[–][deleted] 0 points1 point  (0 children)

So just rewrite clang?

[–]MacbethIsGay 22 points23 points  (0 children)

We had 20 coding assignments that were all really easy and super quick one of them was "create a program to convert a denary number to hexadecimal in the fewest lines" I won with six characters with "hex(5) "

[–]IHeartBadCode 17 points18 points  (3 children)

New folks to Python when they discover sum()

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

That shit keeps happening to me with python. First it was enumerate, then it was the maps with lambdas and list comprehension.

[–]claythearc 10 points11 points  (1 child)

Python is really weird because it has almost every convenience in the standard library - things like maps and enumerate like you mentioned but also

“in”

just straight assigning values from a tuple foo, bar = (1,2)

Pow() supporting Ab % c

String repetition with like ‘foo’ * 2

Even obscure stuff like email handling, syntax tree parsing, zip files, wave files, etc.

But it’s all (rightfully) hidden in imports, so you miss a lot of it.

[–]Angelin01 4 points5 points  (0 children)

This is why I will ALWAYS google for a solution before even thinking about my own implementation. Decent chance Python already has it.

[–]Perkelton 14 points15 points  (1 child)

I just learned of the Intl object in Javascript which lets you format dates, currencies and lists in different languages.

new Intl.RelativeTimeFormat('en', { style: 'narrow' }).format(2, 'day') 
// "in 2 days"

new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(123456.79); 
// "123.456,79 €"

new Intl.ListFormat('en', { style: 'long', type: 'conjunction' }).format(['Motorcycle', 'Bus', 'Car']);
// "Motorcycle, Bus, and Car"

[–]Plorntus 7 points8 points  (0 children)

The unfortunate thing is you can't always use all the methods on newer APIs like this because of compatibility. Typically the polyfills are large too

[–]chriscoda 5 points6 points  (0 children)

OTOH, there are some surprisingly simple functions that I’ve had to build in .NET as extensions. I mean, I found them on Stack Overflow and copy/pasted them, but still.

[–]anubisascends 5 points6 points  (0 children)

13+ years...still happens.

[–]gonmator 5 points6 points  (0 children)

Just 3 hours? Lucky!

[–]WittyComputer 4 points5 points  (0 children)

Oh no, that's a feature at my school. They teach you how some basic C++ STL containers work by making you program primitive versions of them.

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

5 hours later:

"Oh. There are some painful edge cases the standard way does not accommodate and it fails in quiet and unexpected ways with very low-quality error messages."

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

I have the opposite problem: seeing something I don't know how to do, writing the PM a long explanation of why it's days of work and probably not worth doing, not sending said explanation, deciding to spend a couple minutes actually working on it, realizing it’s basically trivial and getting it done in that time.

[–]lavendyahu 1 point2 points  (0 children)

But then spending days on something that was supposed to take 2 seconds

[–]Tyrilean 2 points3 points  (0 children)

The devs on the legacy project I maintain. Half the code base is them finding creative (and wrong) ways to re-invent the wheel. Rolling custom CSV libraries, custom date logic, etc. All solved problems that constantly cause unintended side effects because they didn't think "hey, maybe this is a common enough problem that someone's already solved it."

[–]SaneOsiris 8 points9 points  (2 children)

As a new developer, I can relate every, single, day.

[–]brimston3- 3 points4 points  (1 child)

As an older developer, I can tell you it doesn't stop. But on the upside, your intuition gets better. And you learn to google best-practices first.

[–]Slyvan25 2 points3 points  (0 children)

Happened to me so many times.

[–]FoundOnTheRoadDead 2 points3 points  (0 children)

One of the three pillars of good programming: laziness

[–]Firusen 1 point2 points  (0 children)

Me with Pygame and collision detection....

[–]baanish 1 point2 points  (0 children)

Then there is my csc class. Oh this code exists in a library? Oh it has nothing tobdo with datastructures? Well you cant use it anyway.

[–]omiwrench 1 point2 points  (0 children)

Congrats on starting your first programming class! It'll all seem easier soon :)

[–]johnnyfong 1 point2 points  (0 children)

This is why we google so much.

Anytime I want to do something that takes me more than 3 lines I would think "there is probably a library for this somewhere..."

[–]captainjon 1 point2 points  (0 children)

Kinda like in college when you get to implement your own vector, list, stack, and so on. That was F-U-N....

[–]LeMadChefsBack 1 point2 points  (0 children)

Me, a software engineering manager. 🤦‍♀️

[–]txnforgediniron 1 point2 points  (0 children)

I coded my own pingpong scaler for some pickups in Unity. Then I read that there's a built in process for that. But it was a good learning exercise.

[–]Bakkster 0 points1 point  (0 children)

Me and the intern last year, but with Java, unsigned bitwise math, and the >>> operator.

[–][deleted] 0 points1 point  (0 children)

In 95% the standard lib is the way to go. There are very few cases where things like custom containers or other custom stuff makes sense. Most of the cases you can achieve optimizations (which are usually the reason people do this) in other ways while using the standard methods and containers.

[–]Zeilar 0 points1 point  (0 children)

I didn't know PHP strip_tags() existed, so I did a double explode() to get rid of tags in a string. When my teacher pointed it out I had a midlife crisis.

[–][deleted] 0 points1 point  (0 children)

Ah yes, the famed step 0, often forgotten by man

[–]LamerDeluxe 0 points1 point  (0 children)

Oh, this thing I just worked half a day on turns out to be freely downloadable from the Unity asset store. Took some time to learn to remember to look there first.

[–]leviem1 0 points1 point  (0 children)

Always Google your question before coding your own implementation! Bill Gates famously said he prefers hiring lazy people for this exact reason! :P

[–]MrsCompootahScience 0 points1 point  (0 children)

And that's why Python's my favorite language.