Examples of code

Here’s an example of a password program in C++ I made. Closes right away after doing what’s asked, but it works.

1 Like

The obvious choice: https://github.com/Revolutionary-Games/Thrive/tree/master/src

Though I suppose I’ll link some of my recent code: https://github.com/hhyyrylainen/Leviathan/blob/develop/Engine/GUI/VideoPlayer.h

If you are starting to get into programming, then this is a good early program to make. But, I don’t think this is particularly good code. It has issues like using namespace std should not be used (other than really small learning programs) and most code styles I’ve seen require you to put spaces around operators instead of having no spaces within a line, as that makes reading it much more difficult.

1 Like

First question : why not using “namespace std”? What problem does it cause?
Second question : Can a code without much spaces be difficult for the machine to read?

A ton has been written about this. Here’s what’s on stackoverflow about this:

Code is meant for humans to read. A well made compiler couldn’t care less how you format your code. Formatting is about making code easier for others to read, or even yourself after you come back 6 months later to some piece of code you wrote.

Ok. The only thing I still don’t understand is why “using namespace std” is not recommended. I read the Stackoverflow thread, but I still don’t understand somehow.

It’s also partially a style thing. In order to write code that other people expect and can read easier, you should not use using namespace std. It can prevent some problems, but that is not the main point. A lot of programming is about making code clean in order to make it easier for other people to understand your code.

Here is a program that makes up random full names based on arrays of strings.

EDIT : I’ve put the first name “Gaston” and the last name “Dreyfus” as an easter egg (reference to UFO : Enemy Unknown in which one of the possible names for the soldiers is “Gaston Dreyfus” [in livestreams rediffusions of the french youtuber “Bob Lennon” on the previously mentioned game, he would always keep Gaston Dreyfus alive and he was the hero of the entire XCOM franchise to him{especially at the end of the game lol}]).