How do people learn to write professional looking C++ code...

How do people learn to write professional looking C++ code ? Is there a template how to create directories full of stuff I'm not aware of?

Other urls found in this thread:

google.github.io/styleguide/javaguide.html#s4.1.2-blocks-k-r-style
twitter.com/SFWRedditImages

>professional looking C++ cod
Could you give examples?

I'd guess no

>Is there a template how to create directories full of stuff I'm not aware of?

Companies sometimes make their own templates.

Here's how google writes Java for example.

google.github.io/styleguide/javaguide.html#s4.1.2-blocks-k-r-style

Look out for Carmack's Doom and Quake code.

clang-format

When I write code it's a few cpp and h files, maybe makefiles if I rally want to stretch it.

But when I browse github every little thing is like a forest of shit. That makes it look more complex than it is.

You know what I mean?

each class gets it's own file

each class that is inherited from a class gets it's own file

there, you may now attend your designated shitting street

(multiple inheritance is slow trash btw)

source code of decfon and uplik was released too

Do you think they do it all by hand? How is that practical ?

Fuck you we have a space program India will be a superpower by 2030

>Do you think they do it all by hand?
They have their IDE that will do all of the getters and setters

Also, these projects probably have multiple people working on them

lelele

>template
hehehe

>(multiple inheritance is slow trash btw)
what do you autists even mean when you say shit lik this?

it's probably a couple nanoseconds slower
no one outside the spectrum gives a shit

>a table lookup of virtual functions plus the actual call is only a few nanoseconds slower

I bet you use exceptions too

>is only a few nanoseconds slower
yes it is unless you're on a 20 year old spergbox

I've seen code written by hundreds of different professionals and none of them have the same coding style.

The best way to make your code look professional is to avoid the most common coding mistakes, such as uninitialized variables, unhandled exceptions, bad variable names or very large methods.

It also helps if you write comments in your code, explaining the intention behind what every method or code section does, but most people don't bother writing that anyways.

>It also helps if you write comments in your code
If there is a need for this then you're most likely already going the wrong way about it

Your variable, method and class names should give away that a piece of code is supposed to do, unless you're doing something really complex

>When I write code it's a few cpp and h files, maybe makefiles if I rally want to stretch it.
Because you're most likely making little monolithic turds riddled with completely unreadable, obfuscated shitcode, just like most of /dpt/

Professional code is """complex""" (it isn't, you're just retarded) because it follows some set architectural and design principles, while also making it available for other people to read and extend/fork.

Anything more complex than this is unnecessary

You have no idea of what you are talking about

>video games
in the trash

hehe have a look at some professionnal / commercial level software, like the Cryengine.

Functions are not virtual unless you explicitly mark them to, Pajeet. Git gud.

Sure you can do a class that inherits from multiple other abstract classes, you can also eat your own shit but it doesnt necessary mean you HAVE to. But well, you probably do.

Wow, you've got 10 additional files! Why dont you put all this shit into main!?
Anything more than 1source is too much

The thing you need to learn is cmake.

.h/hpp files is mainly for documentation.
There you declare the functions and give doxygen documents.
Avoid putting the code here (although sometimes one liners are accepted here)
.cpp files is where you implement the functions.
If there is something weird or important, make a comment, but this part should be self documenting.

As for folder structure:
I usually create a lib, bin and build folder when I compile.
I use a cmakelists.txt for the overall project, which is in the root folder.
Then I create a lot of sub folders for different parts of the project.
Each of those sub folders have their own cmakelist.txt so it is easier to manage.

The overall cmake file has the settings etc.
Then the cmake files in the folders are the more specific stuff, where you include the files etc.

It's funny how I've been programming in c++ for over ten years and never cared for making lib, bin, or build folders. I mean, Visual Studio did everything for me, so I guess it was something I never really cared for. Nor have I ever cared for making build or make batch files. It's the little things like this that have me realize sometimes that I'm not as knowledgeable as I should be when it comes to these things. But so far, I haven't really needed it in my professional life.

writing good code is more about design decisions.
and besides that, programmers spend very little time actually programming. most time is spent on reading documentations, source code and trying out solutions to problems until you have the best one.
actual development is mostly research and reading. the actual programming part takes up very little of that overall time because by the time you want to implement your solution to a problem you have (hopefully) found the best way to do it.

Being this retarded.

And this is overrated, because "professional" software is worked on by dozens, if not hundreds, of employees, some of them brand fucking new to the project, and your software is not.

Not everything associated with "profeshenullllls" is a good thing. Sometimes, it's a horrible compromise meant to cater to that retarded sperg they just hired to replace the skilled, socially normal programmer that retired last week.

Just because your IDE does it for you, doesn't mean you shouldn't know how it should be done.
At least you should know the file structure.

Yeah, if your entire codebase is

Creating sub folders for more complex things is allowed only if the structure stays the same. The other option is MVC everything else is shit

>no tests
>Creating sub folders for more complex things is allowed only if the structure stays the same
>everything else is shit
Well done, Pajeet.

>it's a horrible compromise meant to cater to that retarded sperg
that's not the goal at all, what the fuck

it's just that the codebase will turn into an incomprehensible shitfest if a bunch of people start doing things their own way
readability and other common standards also speed up development of projects for a developer of any skill level, because no one likes churning through a million lines of inconsistent spaghetti code

>Sometimes, it's a horrible compromise meant to cater to that retarded sperg they just hired to replace the skilled, socially normal programmer that retired last week.
>the worst-case scenario is bad, therefore we should write minimalistic and unmaintainable code

>TFW working for multi million banking company as software engineer and some random 16 y/o 1337 h4x0r is calling me Pajeet over the internet

>1) Given that the bank's worth is in 8 digits or less, it's a glorified piggy bank
>2) You're working for a banking company and asserting (pun intended) that having no tests is okay
>3) Calling the guy who supports comprehensive testing a teenager, are you for real?
I'm calling bullshit. BTW, I'm 27 and I work for a software company that makes $60mil a year.

isocpp.org

>Don't know if sarcastic or not
I thought this was bad practice, I also put all my code in main.cpp

This. When learning c++ i got through the intro stuff and started reading carmacks code since everyone blows their load over it.

Hes right shitter. The only comment you should write is a description at the start. If you feel the need to write in the middle.you should split shit up so it is simpler.

Go read Carmacks shit. He puts it this way commenting is doubling the work for you and whoever maintains it since you have to now write everything twice and someone has to read it all twice.

If its so complex it needs to be explained make it less complex.

>Not everything associated with "profeshenullllls" is a good thing. Sometimes, it's a horrible compromise meant to cater to that retarded sperg they just hired to replace the skilled, socially normal programmer that retired last week.

This. Companies are not interested in the best way to do things. They want the cheapest. And that is why youll will come across so much shit in your life.

>Not adding comments. You haven't done anything more complex than 8 queens

If it needs to be explained it needs to be split up. Anything more complex will be a pain to maintain no matter how much you write. Computers are machines that execute the simplest commands imaginable. You have options to simplify your shit.

Yeah computers execute simple commands.
Also try programming on assembler without comments

so many shit-eaters and street-shitters on Sup Forums these days

You would think they'd cancel each other out

kek

>MUH 40 CLOCK CYCLES

You can split your shit up into statements that are immediately apparent without going assembly.

Writing comments is writing the same thing twice you dont need to do it if you wrote it write the first time.

Fuck C++ and use Elixir.

Or Rust. (Same fagging)

stop fucking posting this everywhere, shill

Fine... use Rust.

>professional looking C++ code
What does this even mean?

do you even know where you are?

>That parenthetical spacing

>butt_sp*
god that code is ugly

Don't worry, doesn't look like that anymore. Actually, used to look worse.

:^)

i'm not trolling, faggot, your code looks like ass.
and yes, i know that code interfacing with lua is going to look shitty, but at least clean that dogshit up a bit. why do you have a fucking POINTER to a shared_ptr? literally retarded.

>fucking POINTER to a shared_ptr? literally retarded
I need a shared_ptr for compatibility, as the rest of the code references them by shared_ptr. lua_newuserdata() takes a Lua state and an allocation size, and returns a pointer to the allocated, managed memory, which I then placement construct. I then call the destructor manually in the GC function. How would you have done it?

>How would you have done it?
i dunno, i'm just a shitposting Sup Forumsentooman. also i am a little drunk.

funny, but i am involved in a project that uses lua for scripting.

why the additional indirection? it looks like lua is returning a pointer to its own memory, and you want to cast that to a shared_ptr which points to a button.

>cast
Nope, it's a pointer to space allocated for a shared_ptr. Essentially it's like this:
// Get enough Lua memory to hold shared_ptr to image_rsrc
std::shared_ptr< image_rsrc >* rsrc_sp = ( std::shared_ptr< image_rsrc >* )lua_newuserdata(
state,
sizeof( std::shared_ptr< image_rsrc > )
);

// Placement construct shared_ptr with a pointer to a new image_rsrc
new( rsrc_sp ) std::shared_ptr< image_rsrc >(
new image_rsrc(
lua_tostring( state, 1 ),
lua_tonumber( state, 2 ),
lua_tonumber( state, 3 ),
lua_tonumber( state, 4 ),
lua_tonumber( state, 5 )
)
);

// ... Later on during GC, manually call destructor
rsrc_sp -> ~shared_ptr< image_rsrc >();
I'm using shared_ptr to begin with because a given resource/element may be shared across several internal interfaces and/or be a child of more than one other element. Also C++11.

Dumbshit.

This is the directory of a small project I was working on:
├── CMakeLists.txt
├── cmake_modules
├── config
│ ├── config.hpp
│ └── config.hpp.in
├── COPYING
├── include
│ └── projectname
│ ├── common
│ ├── handlers
│ └── system.hpp
├── LICENSE
├── lua
│ └── projectname
├── README.md
└── src
└── projectname
├── bindings
├── main.cpp
├── handlers
└── system.cpp


It was for a small shitty game engine. All things considered I thought the structure was alright.
I guess just at key points in the project you'll realize that it makes sense to group some of the files and put them in a directory.

In mine for example, I had to create a bunch of .cpp files used to interface with various parts of SFML, so they all went in the bindings directory in src (i.e. keyboard.cpp, mouse.cpp, sprite.cpp, texture.cpp). It just made sense to group them at the time, and the result is a neat directory structure.

bump?

>there, you may now attend your designated shitting street

multiple inheritance has no performance impact.

...

Being ncapable of spotting simple sarcasm.

Wow its almost like illiterate pajeet isn't a thing
People write comments to educate the uneducated or incompetent

lot's of good ideas in this thread, keep them coming

no, this thread is poor with poor suggestions for poor programmers.

the fact that you had to ask means that either there is no hope for you, or you just enjoy trolling Sup Forums. for your sake, I hope it is the latter.