C++ 101

>C++ 101
>"You must write ALL code you use yourself, except std::cin and std::cout. If I see strings, vectors, or STL, you fail this class and this year."

Holy shit help me please I am getting raped in my virgin asshole. I have homework for the summer and I can't think of a single algorithm without buzzing out.

Attached: 1532283376177.jpg (468x468, 141K)

Other urls found in this thread:

en.wikipedia.org/wiki/Entity–component–system
en.wikipedia.org/wiki/Component-based_software_engineering.
en.wikipedia.org/wiki/Event-driven_architecture
youtube.com/watch?v=M4sEcIHG0Yc
twitter.com/NSFWRedditImage

Are you doing pseudocode

Is that an insult or what I don't even know anymore.

try making your own vector

Whoever came up with that curriculum should be shot. By not using the STL, maybe they want to teach you C instead.

I am but I have *no* idea if it's any good or not. I mean, it works.
Do I need to add a lot of public methods like At() or Add()/Remove()? Can I not just have my own proprietary stuff or do people expect a level of usability.
My lecturer literally runs suckless or something like that, he is a definite C guy.

Attached: Untitled.png (619x619, 26K)

Are you white?

Sir what does it matter?

figures...

Attached: Untitled.png (1034x351, 20K)

They might try to teach them how to implement a standard library...
>My lecturer literally runs suckless or something like that, he is a definite C guy.
Never mind, was right.

Now make it a template and add capacity in order to preallocate memory.
>I mean, it works.
Good. But how the fuck should we know what your lectard expects?

>has a working dynamic array
>puts public in front of main
Now I know you are just LARPing here.

>preallocate
It says in the specs I must use the exact amount of dynamic memory or I fail this class. Also I must follow good OOP practices or I fail this class.
>template
I don't know

That was just a bump but OP question so far still stands.

>It says in the specs I must use the exact amount of dynamic memory or I fail this class.
That's retarded because much slower.
>I don't know
How about you learn it, then.
There isn't even a question in the OP.

>much slower
Shit you're right.
>isn't even a question
How do I know I'm not writing completely unrealistic bullshit?

>How do I know I'm not writing completely unrealistic bullshit?
If it works you don't. Anyhow, how should we know without knowing the rest of your code.

This is generally what I code like
#include "Word.h"

bool Word::getBold() const
{
return this->fontFlags & fontMask::bold;
}

bool Word::getItalic() const
{
return this->fontFlags & fontMask::italic;
}

void Word::makeBold()
{
this->fontFlags |= fontMask::bold;
}

void Word::makeItalic()
{
this->fontFlags |= fontMask::italic;
}

void Word::makeCombine()
{
makeBold();
makeItalic();
}

Word::Word(const char* text) :
text(nullptr)
,fontFlags(0)
{
copyText(text);
}

Word::Word(const Word& other) :
text(nullptr)
,fontFlags(other.fontFlags)
{
copyText(other.text);
}

Word& Word::operator=(const Word& other)
{
if (this != &other)
{
delete[] this->text;
copyText(other.text);
this->fontFlags = other.fontFlags;
}
return *this;
}

Word::~Word()
{
delete[] this->text;
}

void Word::copyText(const char* otherText)
{
size_t stringLength = std::strlen(otherText) + 1;
char* tempText = new char[stringLength];
strcpy_s(tempText, stringLength, otherText);
this->text = tempText;
}

ostream& operator

Also my lecturer said working code doesn't mean correct code. Correct code has to also be stylish and of good taste.

Dude are you in a bootcamp or Uni?

Well, this better be bait, because your lecturer would be a fucking retard otherwise. Get out of there fast, if you can.

uni, the best in my country. it's about 100 years old and considered elite education.
Nowhere else to go, the next best thing is a technical university (they write K&R C on paper) and bootcamps with literal thugs.

Sounds like your country's priority is keeping is populace dumb and poor. Sorry OP

>considered elite education
>suckless
pick only one

So how do I pass a difficult class? I started reading Clean Code but I just spend 90% the time imagining getting my ass whooped by the lecturer

By not wasting your time on Jow Forums.

I can't stop escaping reality in my own head, I can't stop hearing voices how utter shit my code is and completely incorrect. There's no way to win this lecturer. I Could copy paste code from linux and he's nail me.
Please help, how do I sit down and write code for 8 hours a day?

Sounds a bit kinky op, you should never stop

>they write K&R C on paper
That's where you should go to. Programming without a computer is cool sometimes. I still do it now and then.

>>"You must write ALL code you use yourself, except std::cin and std::cout
>except the worst things about having to use sepples

We all had to take the C exam first semester on lists and that's when literally half the class flew out of this university. 14 people out of 114 newcomers passed. There were 250 students in total for this exam.
Now, OOP, there are about 300.

lol what kind of looney tunes university is that

>My lecturer literally runs suckless or something like that, he is a definite C guy.
Oh shit. That sucks. That means you aren't really learning C++. You are learning C/C++ which is the absolute worst language ever conceived.

Frankly you deserve to fail if you don't know the significance of psuedocode. Didn't you have an introduction to algorithms before this, or is your school some flyover or community college trash?

Attached: file_2.png (500x281, 193K)

data structures and algorithms are the upcoming semester. But fuck me silly, we'll be studying functional and logical programming alongside that and a ton of math.
Franly I can do bubble sort and maybe make binary search in no more than 30 minutes and that's baout it I guess, what more do I need for now?

This, to me it sounds like he's the "hurr C++ is just C with bloat" type and just wants to make you think like that as well. Just hang on and pick C++ properly by yourself later on if you choose to.

Professor said several times Java is a REAL OOP language that sticks and makes its users stick to good object oriented design. Also insults .Net and C# regularly.

> Java
> Encouraging good practices ever.
My condolences, user.

I use C++ primarily and I think OOP is a meme. The fact that your professor equates C++ to OOP is very telling of his lack of experience as a programmer. He has very clearly never had any experience with component based design or event-driven design. OOP features like inheritance and polymorphism should be avoided as much as possible and should only be used when it is the most elegant way of solving a problem (rarely)

Wait... why aren't they using C, then?

>>"You must write ALL code you use yourself, except std::cin and std::cout. If I see strings, vectors, or STL, you fail this class and this year."
lmao Why?

He's had 15 years of experience, how a consultant at VMWare. Can you please elaborate on why inheritance and PM are bad?
He wants us to be hardcore or maybe likes seeing young people suffer.

based

>except std::cin and std::cout

call him a nigger for making that exception of all things

>should only be used when it is the most elegant way of solving a problem
correct
>rarely
not correct.

>Can you please elaborate on why inheritance and PM are bad?
Because it makes it more tedious to make large fundamental changes to a project of significant size. If you make some change to a base class, it can also mean having to change every class that derives from it. That is total nonsense. Also, polymorphism has a performance cost associated with it. This is solved with entity-component design. An entity is essentially just an array/vector of components. An entity does nothing by itself, but may have something such as an id. Each component added to an entity can provide functionality to it. This way, instead of designing a giant inheritance tree adding a little bit of functionality at each layer, you just break all the functionality apart into separate classes. This makes your code easier to maintain in the long-term and easier to change in fundamental ways that would be a major headache in a typical OOP project.

Should've gone with the superior C.

wtf is the point of using c++ if you aren't going to use the only things that make it worth using

Interesting, what's that design pattern called?

Do an array of char or unicode chars and reimplement the features of string.h you need lol

en.wikipedia.org/wiki/Entity–component–system

Thanks a lot.
I needed strtok desperately, so I made my own shitlicking version.

>Thanks a lot.
It might also be worth it to learn more about general component based design en.wikipedia.org/wiki/Component-based_software_engineering. Component based design is also often used with event-driven design in order to facilitate communication between different systems/components without coupling. en.wikipedia.org/wiki/Event-driven_architecture

Algorithms doesn't come before 101 retard.

Why are you mixing java and c++?

A lot of places do this, but normally its nothing crazy.

Java doesn't actually do OOP very well.

I was wondering the same...

You're the bomb ;_;7

Funny thing is, I tried Java and it was so easy and somewhat pleasant to work with.

Java is a higher level language than C++. Higher level languages are usually going to be easier to work with. However, they do not have the same performance.

Because he is teaching C++ and not Python.

>Can you please elaborate on why inheritance and PM are bad
I'm the same person who made this post I wanted to elaborate and state that inheritance isn't automatically bad. However, it's something that should be used with great care. It's not bad in the sense that goto is bad (although I can actually think of a single legitimate use for goto, but it rarely comes up in well designed software). It's just that you don't want to go crazy with it and look at everything through the lens of that style of programming. In my component based engine, I still use a little bit of inheritance. For example, I wanted both entities and components to be able to have unique ids. Instead of creating that functionality twice, I created a base class which has only an id and had them both derive from it. However, each extra layer of inheritance should be considered with exponentially greater care than the previous.

My advice is dont leet Jow Forums do your entire project. I had mine done by some random who aced it for me but it didnt help in the long run at all

Professor Fant?

youtube.com/watch?v=M4sEcIHG0Yc

>My lecturer literally runs suckless or something like that
If this is not b8, holy kek you're in for a whole lot of autism.

Learning C++ in school is BEYOND worthless. Dive into any modern C++ codebase and it looks nothing like the shit you learn in school

Now I just think you're LARPing. There's no way a suckless kinda guy would praise Java.

kek

lol get rekt
can you at least use c++17?

Just code your own lmao

Unironically based

Is this your first programming class? Clean Code will probably vonfuse you more than it will help.

>except std::cin and std::cout
Are you retarded? Write whole standard libraries yourself nigger.

>wow I can't believe that formally learning programming actually involves understanding what the code is doing at the lowest level and not just memorizing APIs like anyone with no formal education can do

>although I can actually think of a single legitimate use for goto
Is that one even still relevant in a language that has exceptions? The only other cases I can think of beyond that are jumping out a nested loop and using gcc's jump-to-label to implement threaded interpreters more efficiently

Write your own string and vector classes from scratch. Maybe you'll learn a thing or two.

There are only two ways of doing main in C++:
int main(int argc, char *argv[])
{
}

and
int main()
{
}

>He writes code that does not smell like cologne
>He writes code that does not listen to Dire Straits

no way lmao poor you

There is a very simple rule about programming: don't listen to people with nothing to show. Trust people who have done something.
In other words, trust people who have created something (like Linux or Excel or Tetris or anything like that) and not assholes who only do books, conferences, etc. but never actually write code. Would you listen to an art teacher who has never painted anything themselves? But somehow they are an expert at drawing lines or some shit like that? No.

The guy who wrote Clean Code, what did he create? Fucking nothing. Linus and John Carmack are worth listening to.

Autism.

>There is a very simple rule about programming: don't listen to people with nothing to show. Trust people who have done something.
programming is one of the fields where that isn't always true because successful programmers often have engineers syndrome where they incorrectly assume their way of doing things is the right way to solve every problem ever
Carmack is pretty level-headed though

>Also my lecturer said working code doesn't mean correct code. Correct code has to also be stylish and of good taste.
I rape kids like him on breakfast

>agh

lol get fucked

For someone who has been programming a long time and knows C very well, can I get away with just reading A Tour of C++ (2014)? I want to waste as little time possible and don't want to fill my head with a bunch of useless shit, but I do have to learn C++ unfortunately.

>jumping out a nested loop
That's exactly what I was thinking when I said that. However, if I am to be completely honest, I don't think any of my projects that I still have lying around have needed that.

>I rape kids

Attached: this-topic-interests-me.jpg (438x512, 88K)

>my lecturer runs suckless
i use their software too, i unironically feel sorry for you

Memory cleanup is more streamlined through gotos

>cniles talk shit about c++ for years
>incapable of replicating the simplest parts of STL because its too complicated

: (

i always code this way.

my own array makeing and hadleing subclass

I would get along great with your lecturer. I'm a C guy, and have to learn nodejs. Kill me now.

This.

your lecturer sounds like a sick cunt

The way Java in oarticular does OOP is retarded, and IMHO the reason people hate OOP in general.
Classes make sense for entities that have some kind of internal mutable state and offer member functions thst operate on it, the most obvious example being containers: it just "feels“ right to have classes for that, and that's the way they are implemented in the STL.
But being forced to put pure functions in a class is absolutely braindead: most Java code I've seen needs to create all these "Manager" or "Listener" classes that don't even have any internal members. This stuff is bad style both from an OO point of view and from a peocedural point of view. In C++ or Python you can instead just write your functions separately, preferably wrapping them on a module or namespace to avoid name conflicts and better organize your program.
Java is WAY too restrictive in this regard.

>not **argv
pointer degradation m8

This, people like Uncle Bob are hacks.

Come again?

>using pragma once
>while you already made a header guard

Not doing:
auto main(int argc, char* argv[]) -> decltype(int)
{
}

write your own libs faggot

Tell the department head that this guy is a retarded op.

That's all you can do.