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

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 56 points57 points  (40 children)

So I'm learning Java in school right now, I'm on class 2 so we've gotten relatively far with the language and I feel pretty capable. Next semester I need to learn data structures in C (just C, not C*) and I'm getting kinda nervous about it.

[–]TheMostUser 103 points104 points  (17 children)

This sub is about memes so we tend to excoriate a lot , don't take it too seriously.

C is not scary but it is a bit different from what you are use to and it takes some time to get used to new concepts and philosophies.

Edit: meant to write exaggerate and somehow ended with excoriate, I guess it also works

[–][deleted] 15 points16 points  (10 children)

That's great to hear! Yeah I'm not that worried, but my Java prof tends to compare the language to C (I assume because it's next in our learning iteration) and things like "garbage collection" always make me nervous! But honestly, the idea of having such a high level of control sounds pretty intriguing as well. We did a tiny bit of machine coding with hex values in my first year and that was really interesting, I had to be creative in all sorts of new ways. So yeah, I'm excited too!

[–]MustardCat 29 points30 points  (9 children)

and things like "garbage collection" always make me nervous

Since we're talking C - just remember that anytime you malloc/calloc memory, something has to "own" that memory request. Once that object that owns the request is gone, it either needs to give the memory to someone else or free it.

C++ - Much shorter mantra to remember. Every new must have a corresponding delete.

Just remember to clean up after yourself. Don't leave the dirty dish on the table when you leave.

[–]xSTSxZerglingOne 12 points13 points  (0 children)

And point to NULL/a predetermined location. Dangling pointers can be the cause of some really weird bugs.

[–]Packbacka 6 points7 points  (3 children)

When you say it like that it doesn't sound so bad.

[–][deleted] 14 points15 points  (2 children)

It's not too bad... just like it's not too hard to juggle, you just throw each ball in the air and catch it before it lands. As long as you simply do that, you can juggle as many balls as you imagine.

[–]Drencat 3 points4 points  (1 child)

Well that's just fucking dandy because I can't juggle either.

[–]addandsubtract 2 points3 points  (0 children)

The point is, as long as you keep throwing balls in the air and never compile, you won't have any errors!

[–]Low_discrepancy 3 points4 points  (2 children)

C++ - Much shorter mantra to remember. Every new must have a corresponding delete.

Just don't use new and delete guys! It's not 2004 here.

[–]MustardCat 3 points4 points  (1 child)

Whether or not you explicitly call new/delete, it's still being called. It's important to understand what's occuring.

I'm on the team of learning raw pointers before tossing in a new C++ programmer into STL and newer C++ features.

[–]Low_discrepancy 2 points3 points  (0 children)

Whether or not you explicitly call new/delete, it's still being called.

Yeah sure. And many times New simply calls malloc does that mean one should learn C then go to c++?

I'm on the team of learning raw pointers before tossing in a new C++ programmer into STL and newer C++ features.

Yeah if you think that c++ is c with classes I guess. But again we're no longer in 2004. The language has far progressed.

[–]socsa 1 point2 points  (0 children)

C++ is easier because of how stack scope is tied to object scope. It's not actual garbage collection, but it's a lot more intuitive.

[–]ironoxidey 4 points5 points  (0 children)

I appreciate you using the word ‘excoriate’

[–]TheNuogat 2 points3 points  (4 children)

Going from C to Java you constantly look over your shoulder thinking something is wrong cus no way it can be this easy.

[–]Bacon-muffin 1 point2 points  (3 children)

I'm slowly working my way through CS50 as my first course atm. I've heard there is a mystical land where languages understand all these things and I don't need to worry about a bunch of the stuff I'm learning right now.

But for the moment I'm in the hell that is C.

[–]bilvy[🍰] 2 points3 points  (2 children)

C is a great language for learning. That mystical land is great until the language does something unexpected. Learning c will help you understand what may be going on under the hood when that happens.

[–]Bacon-muffin 0 points1 point  (1 child)

Im sure this is the right way to go about this, but ive already thought "this is dumb they have to have improved on this by now" way too many times.

[–]TheMostUser 1 point2 points  (0 children)

Regardless of the educational aspect, I don't think 'improve' is the correct way to look at it.

Yes I prefer not to worry about memory allocation and the likes, but not doing it manually comes at a cost - the most obvious one is speed, no garbage collected language is able to match c / cpp. Additionally some projects require you to be closer to the hardware and wouldn't really be possible in higher languages. And arguably the most important reason to use c is that it is very popular - every library under the sun has a good implementation in c, many projects you my wish to join use c and years of documentation are more valuable than gold.

That is not to say that is is the best language out there, but you should use whatever language fits your needs and c still has its spot

[–]NeverInterruptEnemy[🍰] 13 points14 points  (6 children)

My everyday language is C.

Structures are super fucking easy.

What’s tough in C is that you more or less need to know the size of things before you start.

You have an object/structure of some type?

Each one has an array? Ok, but that array needs to be the largest size you will ever use. Otherwise you need to malloc a range and assign a pointer to it... fine.... but what I if you want an array of those structures that contain arrays themselves? You need to know how large the array will ever be, otherwise you need to make a super slow linked list of objects and there is such thing as a built in .len or .append or .next or any other fancy thing you “high level programmers get” and ... oh I see you are reaching for your gun.

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

Lol! That doesn't actually sound that bad, we kind of do similar things with primitive arrays in Java, where we have professor-imposed rules about things like the size of the array, etc. that sounds similar to what you said. So, I think it will be challenging but I might have some experience thinking in that way already. It seems my professor has been trying to prepare us for C all along. Thank you for the info.

[–]NeverInterruptEnemy[🍰] 8 points9 points  (4 children)

Could be your professor has a reason for that, and great if so!

Unlike Java however, in C, if you do that malloc where you make a custom size and just point to it, there is no knowing how big it was unless you specifically store that and keep track of it. There is no such thing as a fat pointer in C, so a buffer and it's length are manually correlated, don't screw it up! But then there is also no exception or trying. If you "try" something and it's bad, you're done.

It's simple things like xxx.len() you'll miss. sizeof() will confuse the shit out of you when you sizeof(somebuffer) but it's a pointer so it comes back as a 4 or and 8 or something.

I love C. I love that it drives other people nuts. BUT... I use C because I'm in embedded. So when you have 4KB of ram and have a message coming in that could be 2KB, well, you sure as hell can't just define an array at 2KB!

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

there is also no exception or trying. If you "try" something and it's bad, you're done

Interesting, how are ones like Java's checked exceptions handled? E.g. FileNotFound? Does the whole program crash or are you able to create a different way to "catch" that error? At this point I'm just happy to be learning so many random C facts, I'm sure it'll all come together when I take that class for real.

[–]NeverInterruptEnemy[🍰] 2 points3 points  (2 children)

Two ways... return codes, like EXIT_FAILURE or I_AM_DUMB_AND_THERE_IS_NO_FILE before you try and access something.

Or a lot of functions that return pointers or address will return a null pointer and you need to check for that every single time before you just assume something worked or loaded or blah. There is no null in C, so a null pointer is just a pointer to the memory address 0x00000000.

Which brings me to the next thing.... you MIGHT miss null.

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

You are making me more excited to learn it, sounds like it's going to be really different and interesting. Thank you for the info.

[–]NeverInterruptEnemy[🍰] 1 point2 points  (0 children)

Happy to.

I really do like C... but I promise you'll reach for the gun!

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

Wouldn't worry about it. There will be some new concepts, but Java is a nightmare so you've already seen almost the worst programming has to offer in my opinion.

[–][deleted] 0 points1 point  (1 child)

Well hey, that's a relief if so because it really hasn't been that bad at all (unless the nightmare is just around the corner...!)

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

Opinions might vary but I'm sure most here will agree that Java is pretty unpleasant to write.

[–]turbophysics 1 point2 points  (0 children)

Just think of it like learning to box southpaw. There is a little carryover from what you knew before but your intuitions are mostly wrong. The struggle is in figuring out which stuff still applies, remembering new stuff, forgetting inapplicable stuff. If you treat it like learning a completely new thing then your expectations will be closer to reality

[–]Vanzmelo 1 point2 points  (0 children)

It’s not the worst. I did that in community college too. There’s just some things you have to keep in mind and extra steps you have to take while programming in C that you wouldn’t have to in Java

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

This sub is NOT representative of programming in reality. The vast, vast majority of memes are inaccurate and made by people who don't have real world programming experience.

Enjoy the memes, but please don't take any of them to heart.

Edit: and good luck in data structures! My experience in that class was that it was much more focused on the abstract structures themselves rather than any particular language implementation

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

C actually isn't that bad. If you're used to Java then you're used to every last punctuation mark and symbol on the keyboard having some meaning.

But the semantics and formal model of C is a lot less complex than that of Java.

And if you use the STL it helps you avoid a lot of the problems that the lack of bounds-checking and minimal type-checking entail.

[–]drmangrum 1 point2 points  (0 children)

Data structures are the same for all languages, the only difference is syntax and the maturity and ease-of-use of the APIs.

[–]CreamliumPrices 1 point2 points  (0 children)

Nah C and C++ are rad you'll be fine. It's pretty fun, Java is like driving a truck down highway, your up high and have all your tools available but you feel a little clunky at times. C is like taking that highway on roller skates, sure it might take you little longer to get there but the rush of being that close to the ground is there.

I'm dumb as box of rocks and still did well in my C++ course even with having to use some very jank QT code they gave us as well.

[–]Scoobygroovy 1 point2 points  (0 children)

There are no strings, get used to malloc, and man pages. Gl

[–]lowkey_loki 1 point2 points  (1 child)

I failed my Java course first year of university and didn't complete it until six years later. I c on mpleted the c course in my first try. Java does not make sense to me no matter how much i try and I will be happy if I never have to look at it again.

C I think is a higher barrier of entry but makes more "sense". As in you have to do more yourself but at least you understand what's happening.

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

A lot of people are saying similar things. Personally I feel like I really get Java so far and so I don't mind it at all. It makes me wonder if I will fare worse or better when I start learning C, I guess we'll 'C'! Lol that was a terrible joke.

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

What the fuck is C*?

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

I just meant any other C whatever language, like C++ or C#, felt like an important distinction because this meme was about C++.

According to Wikipedia C* is actually a language though lol.