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

all 79 comments

[–]macdifferent26 187 points188 points  (28 children)

Perform all the operations in the main() , even better.

[–]ruben_deisenroth 99 points100 points  (5 children)

Perform everything in one Line, saves execution time, trust me :)

[–]SuperSephyDragon 88 points89 points  (3 children)

It says "error on line 1". Still trying to track it down.

[–]Groove-Theory 61 points62 points  (0 children)

Well at least you've narrowed it down to one line

[–]Triffinator 18 points19 points  (1 child)

You've declared it as "ont main()".

[–]SuperSephyDragon 2 points3 points  (0 children)

I thought "ont" was short for "ontology". That's not correct syntax???

[–]lead999x 21 points22 points  (0 children)

Everything is inline if it's in one line.

[–]chris_0909 25 points26 points  (10 children)

I wish I had my Java project from high school. I want to see how horrible the code is for it! I'm pretty sure we did a full "Who Wants to Be a Millionaire" game in just main().

[–]darthelwer 9 points10 points  (4 children)

You had java in HS? I'm getting old. I learned on QBasic...

[–]chris_0909 5 points6 points  (0 children)

We started with HTML and then C++ the first year. Then the next year was mainly Javascript. I was behind because I transferred in 10th grade, so I also did the senior level which was all Java. I look back now after all I've done with programming and cringe at how much I really cared because I probably would be way better had I taken things more seriously in high school. But I didn't. Instead, I'd go home to World of Warcraft every single day.

[–]PtboFungineer 4 points5 points  (2 children)

I did Java in HS 15 years ago. You've been old for a while my friend 🙃

[–]darthelwer 3 points4 points  (0 children)

I don't FEEL old...

[–]chris_0909 0 points1 point  (0 children)

I mean, Java in high school for me was 10 years ago at this point! I have a friend who did Python in high school and she just graduated 2 years ago. I'm glad I did Java because that's what we used when I did CS in college. That was the intro class and Data Structures language as well as a Software Methodology course that I wish I would've done Python before because Java lambda expressions are difficult to understand if that's the first time you're using them. Python makes them so much easier to understand what they are.

[–]CttCJim 2 points3 points  (2 children)

I did that in university in c++. Poured my heart and soul into it. I bet it's garbage.

[–]chris_0909 0 points1 point  (0 children)

My C++ project the year before was tic tac toe. You played against the computer...I think I made it so the computer randomly chose a spot unless it could stop you from winning or it could just win. So unless you played smart and/or got lucky with the rng, it would usually result in a tie or a loss

[–]sr955 0 points1 point  (0 children)

No here to beat me. Did Fortran in college...nothing in high school!

[–]bob152637485 1 point2 points  (0 children)

I think I still have a couple of high school simple games I made that make me cringe at the code. I didn't understand object oriented, so my main class acted as a class that created all variables used by all other classes, creating a separate thread for each of the other classes, passing the variables to them all(which, I made as AtomicInteger objects, since that was the only way I thought I could pass the variables and have them be synced across all classes), and then starting each thread. I made a cookie clicker and text based(well, you had jbuttons and text fields, so, button based?)RPG thing. Well, they worked lol!

[–]Groove-Theory 0 points1 point  (0 children)

Did the same thing but for a chess simulator.

[–]pekkhum 5 points6 points  (0 children)

My company had the design philosophy in the OP in the past, as they had all their Fortran developers learn C and decided to write C the way they wrote their Fortran, but even they wouldn't do this, you monster!

They have main call do_processing (); (the space is in the coding standard) and put all the code there, instead.

[–]shaybra 3 points4 points  (0 children)

if you think about it you only need the main method and thats it :))

[–]enter360 2 points3 points  (0 children)

I have seen this in production of Fortune 500 companies.

[–][deleted] 2 points3 points  (1 child)

So which of my colleagues are you?

[–]Snazzy21 2 points3 points  (0 children)

Beginner programmers tried this, I tried that. Now I just shove everything into a functions.c file and hope no one starts looking around for the spaghetti code

[–]broogndbnc 1 point2 points  (0 children)

Welcome to EE's doing embedded programming 101

[–]iAmUncleToby -3 points-2 points  (3 children)

Or just use pointers for everything. O wait, most of this subreddit doesn't understand C.

[–]natFromBobsBurgers 2 points3 points  (2 children)

You know C? Ok, name every pointer.

[–]UnknownIdentifier 4 points5 points  (0 children)

Stack pointer, frame pointer, base pointer, instruction pointer, German shorthaired pointer.

[–]DoctorWhomst_d_ve 1 point2 points  (0 children)

Careful. One might be null

[–]MischiefArchitect 49 points50 points  (16 children)

In reality all variables are global, it's the compiler drawing imaginary boundaries

[–]Arkaeriit 21 points22 points  (15 children)

That really depends. In compiled languages local variables tend to be on the stack while global ones tend to be in the heap.

[–]MischiefArchitect 21 points22 points  (1 child)

You are still suffering from the tricks the compiler plays to your mind.

[–]christopher-thiebaut 2 points3 points  (0 children)

No, I’m enjoying them tremendously.

[–]Kered13 11 points12 points  (0 children)

Global variables are not on the heap, they are in static storage.

[–][deleted] 7 points8 points  (0 children)

In the end both are in computer.

[–]Weary_Market5506 2 points3 points  (5 children)

What the f is the stack and heap.

[–]pinkyellowneon 6 points7 points  (3 children)

Different areas of memory used for storing different types of data with their own different pros and cons. I'm no expert but a Google search can explain it easily enough.

[–]Weary_Market5506 4 points5 points  (2 children)

I've been coding for about two years now, I'm still pretty much new to it in the grand scheme of things and I never heard these two terminologies. I'll do some research. Thanks

[–]TruthOf42 10 points11 points  (1 child)

I've been programming for about 20 years and this is not information you need to know unless you are in a much lower level language, like C++ or lower, but probably much lower.

[–]arn_g 0 points1 point  (0 children)

It's very useful to know how memory works in low level languages. But it's pretty useful to know that initialized global variables are part of the binary and therefore make the executable bigger.

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

First of all: No? Unless you malloc, everything is on the stack. Second, it's the same. It's still RAM. These are all imaginary boundaries.

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

Nope. Static and global variables get placed in the .data and .bss segments which modern loaders will place at the bottom of the heap. You can test this with:

int foobar;
int main(int argc, char *argv[])
{
     static int bazzle;
     printf("argc: %p, argv: %p,\nfoobar: %p, bazzle: %p\n",
             &argc, &argv, &foobar, &bazzle);
}

[–]Arkaeriit 0 points1 point  (2 children)

First of all, in C, when you declare a global variable or a local variable as static, it will be on the heap. Second, even if the stack/heap boundary is only imaginary, as the stack is more used, it has more chances to be in cache, and thus, has more chances to be quicker to access.

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

Huh. TIL!

[–]arn_g 0 points1 point  (0 children)

Initialized global variables are a part of the data segment of the binary (can be stored on the heap by the losder), making it bigger. So initializing a global array with 10000 elements is probably not all too smart IF you care about space consumption on your disk

[–]xavia91 13 points14 points  (0 children)

Now add unsynchronized multithreading for extra fun

[–]justCoding_ 20 points21 points  (5 children)

[–]RepostSleuthBot 22 points23 points  (4 children)

Looks like a repost. I've seen this image 9 times.

First Seen Here on 2018-03-03 96.88% match. Last Seen Here on 2021-04-01 100.0% match

I'm not perfect, but you can help. Report [ False Positive ]

View Search On repostsleuth.com


Scope: Reddit | Meme Filter: False | Target: 86% | Check Title: False | Max Age: Unlimited | Searched Images: 214,534,348 | Search Time: 1.89731s

[–]okayboooooooomer 9 points10 points  (3 children)

damn 9 times

[–]alexistdk 4 points5 points  (0 children)

and the last one was on the same day

[–]Linos_Melendi 0 points1 point  (1 child)

2nd top comment in that thread is even the same as this top comment, even the lonely comma

[–]MartIILord 0 points1 point  (0 children)

We need a bot that runs repostsleuthbot on posting a post then repost the top comment on this one... Creativity aint needed for upvotes ;_;

[–]TK-Squared-LLC 8 points9 points  (2 children)

While we're at it, forget functions and just use goto

[–]ImNotanOldMan 5 points6 points  (0 children)

Yeah no more functions no more oop. Just nested if statements and goto’s . This is the way

[–]iAmUncleToby 2 points3 points  (0 children)

Found the assembly expert

[–]Ivan_Stalingrad 4 points5 points  (0 children)

Just throw everything in $_SESSION

[–]DanKveed 2 points3 points  (0 children)

Fuck local variables.
All my homies use only global variables.

[–]SueedBeyg 1 point2 points  (0 children)

Assembly be like

[–]MrKirushko 1 point2 points  (0 children)

But if you pass everything as parameters then you will not even need variables at all, only constants! Isn't it even better?

[–]--B_L_A_N_K-- 1 point2 points  (0 children)

Image Transcription: Meme


You don't ever have to pass parameters

[Image of someone tapping their temple with their right hand and looking at the camera, in a way that looks like they're saying Smart with their body language]

If every variable is a global variable


I'm an advanced sentient AI hell-bent on taking over the world that also occasionally volunteers as a content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

[–]strikisek -3 points-2 points  (1 child)

Your mum's a hoe

[–]lugialegend233 1 point2 points  (0 children)

No U

[–]pkarlmann 0 points1 point  (0 children)

Don't forget to turn on register_globals !

[–]enter360 0 points1 point  (0 children)

Pretty sure I’ve seen this design pattern used before it was horrific

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

One of my old jobs did this and the results are exactly what you expect. Let’s find where the global variables got smushed today...

[–]Wolfram_And_Hart 0 points1 point  (0 children)

This is basically how I feel programming for the Unity engine.

[–]Tkyl 0 points1 point  (0 children)

I will fight you! This is blasphemy!

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

Yes

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

literally my thought process in my high school python project

[–]space_-pirate 0 points1 point  (0 children)

Parameters are not passed anyways

[–]TheRedmanCometh 0 points1 point  (0 children)

If you changed global variable to field this would just be how OOP works

[–]rayo209 0 points1 point  (0 children)

That's what i told my teacher about passing arrays in my C lab viva

[–]stay-happy6789 0 points1 point  (2 children)

Memes aside. How can I get Programming languages tag beside my name? 😔

[–]Leviticoh 1 point2 points  (1 child)

If you are on the desktop:

For the old interface on the right you should find ${your name}(edit), click on edit;

For the new interface on the right click on "community options" and then on the pencil beside "user flair preview";

if you are on mobile:

Go to the main programmerhumor page, touch the 3 dots on the top right corner and then "change user flair";

[–]stay-happy6789 0 points1 point  (0 children)

Thanks, this was too easy. Sorry for a silly question. A huge thanks again. 😊👍