General questions and guidance from pros

Pages: 12
Hi everyone,

I'm in an online C++ video class, about 46 hours of instruction. I'm about a quarter of the way through the class, really enjoying it and excited to learn more. I've also been watching Uncle Bob's lectures on clean code and proper structuring principles, and although I don't know the language yet, I am gaining a ton of insight for future reference when I start structuring larger projects and time management, etc. The only thing I feel I'm lacking is a mentor or a group of pros that I can bounce questions off of and such, so here I am. Thanks for this forum.

My main questions as of now are these:

1. What IDEs/compiler/etc combinations are generally accepted as professional, complete, and on par with companies? I know any of them will work, but I'd rather try to get used to what is used by professionals so if I ever get picked up by a company, I'm a little closer to being in the loop. Currently I'm using visual code, but not for any particular reason.

2. Speaking of Uncle Bob and clean code, he specifically talks about making code organized, easy to read by yourself and others, self-explanatory, and the simplest yet most effective it can be, more importantly doing that from the start. I as a person am all about that, so I'm trying to instill those coding habits right now. I'm writing a metric clock (not a converter from minkukel time, but built from the millisecond up) and while the actual effectiveness of the code is a different question, is my code organization up to par, and would this method of writing and formatting make a professional go "oh, jesus" or am I on the right track to move forward with this style? Understandably this is a simple program and doesn't showcase much complexity.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <iomanip>
#include <windows.h>
using namespace std;

int main(){
    int sec {0};
    int min {0};
    int hr {0};

    while (true){
        cout << "\033[2J\033[1;1H";
        cout << setw(2) << setfill('0') << hr << ":" << setw(2) << setfill('0') << min << ":" << setw(2) << setfill('0') << sec;
        ++sec;
        if (sec == 101) {sec = 0; min++;}
        if (min == 101) {min = 0; hr++;}
        if (hr == 11) {hr = 0;}
        Sleep(864); // number of milliseconds in a metric second, which drives the entire while loop
    }
}


3. What are some things that professionals or companies look for in terms of hiring fledgling programmers, is it existing knowledge of the code? Ability to learn and grow? Good professional/team dynamics? For sure it's a combination of all these things. But with some companies I've worked for in the past (not in programming) I was surprised to learn that straight knowledge is not always desirable to them, moreso ability to learn and grow in their environment. So I'm just curious about the industry and want to hear from pros.

4. What sort of programs or skills look good in a personal portfolio, or do these portfolios even matter much to an employer? I would think it beneficial to show what I've written being self-taught (except for video classes) but maybe I'm wrong there. And on that note, will anyone give me the time of day being self-taught/online taught? I have no college/university but everything I've done in life has been self-taught and I'm a fast learner.

Thanks for any help. Just trying to zero in my compass needle in this new world.
1. For an IDE, you should use what you're comfortable with. If you prefer to work with a plaintext editor, do it. As long as you're productive, I've never heard of anyone who cares. Speaking for myself, they can pry Visual Studio from my cold, dead fingers.
Now, as for the compiler, the compilers in most use today are MSVC, GCC, and Clang. Other compilers exist, such as Digital Mars and Intel, but these are much less popular; the former just is, and the latter is expensive. You will usually need to use one or another, or some combination of multiple compilers, depending on the nature of the particular project you're working on. For example, if your project is for Windows, you would default to use MSVC. On Linux your default would usually be GCC. On BSD and MacOS, the default would be Clang. If the project is multiplatform you'd first develop on one compiler and then ensure that your code build on all the supported platforms.

2. Avoid very long lines that trail off way to the right. For a print statement that's not so important, but it's better to avoid it all the same.
Avoid cute things like if (sec == 101) {sec = 0; min++;}. Just write a single statement per line. Don't worry, you're never going to print the code listing.

4. Unless it's something you can show off quickly, most people don't care about portfolios and won't bother to peruse your Github profile if you link to it. "Show off quickly" means they can follow a link and see the thing in question up and running. Thus portfolios are mostly only relevant for web front-end people, and basically completely irrelevant for C++ people. The only exception would be if you've worked in something that overlaps in some way with what the company want you to do if they hire you, but that's a crapshoot, not something you should aim for.
Good to know, thanks for all that.

Avoid cute things like if (sec == 101) {sec = 0; min++;}. Just write a single statement per line. Don't worry, you're never going to print the code listing.


Unsure what you mean by this. In my mind that is one statement per line (if, then:), do you mean I should separate the if and then, and what's the purpose of making more lines than is needed if it all fits right there together? Is it a readability thing?
Well, using namespace std; is likely to not be something looked on as a good thing by most companies.

The best advice is to research a company you are looking at for employment. If at all possible ASK what they would consider desirable with a new hire. And see if they offer an (usually unpaid) internship.

I am a self-taught (still doing it) C++ hobbyist programmer. The best advice I can give? Code, code and code until your brain is mush and your fingers bleed. (Not really, but close).

Most of the code in books and online is either close to be trash, outdated or so rudimentary as to be virtually useless.

There are a couple of free tutorial sites around that are decent, if not comprehensive for what C++ has to offer.

The tutorial here (http://www.cplusplus.com/doc/tutorial/) is definitely out-dated, no C++14 or later. But then a lot of the core of the basics of C++ are still shown.

Learn C++ (https://www.learncpp.com/) is being updated, another C++tutorial site that doesn't cover all of what the current C++ standard has to offer. Still lots of good info.

Both sites have examples you can muck around with. Something I highly encourage.

I personally prefer Learn C++.

Online reference site cppreference (http://en.cppreference.com/w/) has up-to-date info on C++20, the current C++ standard, with examples. But this is not a site to learn C++. It is a very technical reference oriented site.

There is one book I do recommend as one to learn from as well as being a good reference, covers a lot of what is now considered Modern C++, including C++20.

Beginning C++20: From Novice to Professional
https://www.amazon.com/gp/product/1484258835/

I recently purchased it (I have several dozen C++ books, print and eBook) and it is one of the better "Learn C++" books I own. Other books are specific to a specific C++ standard or part of the language, such as lambdas. Or were written for earlier C++ standards.

Older code I run across (or is part of one of the "Learn C++ books I own) I "revisit" and see what it might take to update it for later standards. It certainly isn't boring, and doing it makes me think.

What works for me may not work best for you, after all I am not someone who is programming employment oriented. For me learning C++ is a hobby. Intellectual curiosity. If I have any goals they might be to throw together some code to create games. Both console and WinAPI GUI.
what's the purpose of making more lines than is needed if it all fits right there together?
Why did you write your code in 20 lines when it fits in just 7?
1
2
3
4
5
6
7
#include <iostream>
#include <iomanip>
#include <windows.h>
using namespace std;int main(){int sec{0};int min{0};int hr{0};while(true){cout
<<"\033[2J\033[1;1H";cout<<setw(2)<<setfill('0')<<hr<<":"<<setw(2)<<setfill('0')
<<min<<":"<<setw(2)<<setfill('0')<<sec;++sec;if(sec==101){sec=0;min++;}if(min==
101){min=0;hr++;}if(hr==11){hr=0;}Sleep(864);}}


Is it a readability thing?
Obviously.

In my mind that is one statement per line (if, then:), do you mean I should separate the if and then
By "statement" I was referring only to the ones that end in a semicolon.
Here are the rules I use:
* Only one semicolon per line. Exceptions should only be made for the sake of readability. Visual compactness of the code is not an optimization goal.
* Statements and declarations that have "headers", like if, while, for, switch, case, and class and function declarations, should have those headers on their own lines and never mixed with the contents of the inner block (except, once again, where it increases readability). This is because those syntactical elements have special purposes other than merely modifying the state of the program, and thus should be spatially separated from normal sequential statements. Namely, they modify the flow of control through the code and change the set of names that are available in some particular context.
* For the same reason as above, standalone blocks should have their opening and closing braces on their own lines, since those braces dictate the start and end of a new scope. Like this:
1
2
3
4
5
foo = 42;
{
    auto bar = foo;
    baz(bar);
}
Not like this:
1
2
3
foo = 42;
{auto bar = foo;
baz(bar);}
I learned a new word today.
Minkukel.
MINKUKEL!
Minkukeldomkop!

That was fun.

About the IDE question:
You should treat an IDE like you would a writing utensil. It is considered bad form to switch between pen and pencil between projects, however you might look silly if you were asked to write with a pen and it caused you to hesitate because all you've ever written with is a pencil, yes? <- But the interviewer would be more understanding if you say clearly "Oh, I've never used Eclipse before, this will take a second to get used to".
Practice on Visual Studio until you feel confident with the language, then branch out to using Code::blocks, Netbeans, Geany, Eclipse, etc., If you can practice the same language on a couple of IDEs then you'll have a pretty good understanding of IDEs in a more general way. Coming across a new IDE will not be so confusing.

Once you have mastered C++, then the language itself might be viewed in the same light, it would be a good idea to also learn Java, Python, or an even newer language. Maybe you are better at telling a story with a paintbrush than you are with a pencil.
Last edited on
the one statement per line thing varies. The key is consistency in style and readability, along with whatever your boss says. But in my book its ok to say
if(cond){statement;}

if there are multiple statements in the if, though, no -- everyone's tolerance varies but that is my limit.
many people jumble if and else together, technically 2 statements, but
else if(second condition) is common.
many people think the ? operator is ok on one line when an if is not to do the same thing. Its weird how coders can be about such things.

if (sec == 101) {sec = 0; min++;}
could be simplified away (whether you should or not is another question, its a little harder to read)
min += sec==101;
sec %=101;

Sleep isnt ensured. It could sleep 1500 or whatever... sleep suspends the process and it cycles back when at least that much time passed, but not exactly. This clock will drift badly.

re style. Most (all good ones) companies involved with program development will have their own coding style (coding manual). When coding for that company (in whatever capacity) you would be expected to follow their coding style. This particularly refers to use/not use/placement of {}. Wars have nearly started over how/when these are written. Have your own style, but be prepared to change to that of the company.
1. IDE is just a tool to help you write and compile your code easily. There is no porfessional standard as far as I know. I personally prefer to use CodeBlocks. For a recent project, I've been using Visual Studio (I absolutely hate this thing. It puts MSVC dll dependencies in a console app). I have a friend who works with me and uses text editor. He just writes code in text editor and then compile from terminal. It's entirely up to you. You can use any compiler you find comfortable as long as you complete and deliver your task as per demand.

2. Code is not bad. Try to break down that second cout line into multiple lines. The ifs are okay with me if it's just one statement but don't make it a habit. Using using namespace is actually considered bad practice by many (I love to use it). At least don't use it in header files. Your code here doesn't require much comments. But in practical cases, you should write comments explaining what a variable is or what a function does etc. You should make a habit of writing such comments. Otherwise, in larger projects, after a month you'll forget what that variable/object was for and what that function is doing.

3. I have no idea. I am working part time for a new company. Me and my friend are the first official programmers there. I just went and said that I can program in c/c++ and python and they hired me. Maybe because they are new. Absolutely no idea what big companies want. About knowledge, almost half of what you learn will be useless when you start working and you'll almost always have to learn something new. So, as long as you know the basics of c++ and know how to implement a given algorithm, should be fine.

4. Unless you have contributed to a well known/popular library or software, doesn't matter. Most employer wouldn't bother to go through your personal projects to gauge your ability. You can try to cook up some small apps/tools that can be packaged into a single binary. Maybe some employer will check your program if it can be run immediately.

Final advice, practice a lot. This is one of the fields where practice and experience are way more important than theoretical knowledge.
@Rakib771, you do realize you can change MSVC's dynamic library linking to static linking, right? You can even make it the default if you so choose.

I am the exact opposite, I despise having static linking producing even simple apps that end up taking several hundred KBs of space, when MSVC apps create a size of around 10KBs via dynamic link.

If'n I want to release something into the wild, after lots and lots of revisions and testing, then and only then do I static link the final version.
its not the only one -- at least M$ libs are already on your machine, so you don't have to ship with. I used to distribute to my peers cygwin compiled stuff and you had to give them the dlls it linked to near every time.
The fact that your asking the questions is a good sign.

Many top universities like MIT and Stanford make their lectures available online for free. So you can take create computer science courses, albeit without getting credit. If you take the course from a year or two ago, you'll probably be using an older revision of the textbook, which will be available for like $10 vs. the $250 that new textbooks for for these days.

As for coding in general:
- I find it easiest to work on the data first. Then work on the code to deal with the data.
- Here's a very powerful mindset: your functions and methods shouldn't "do the work." They should make doing the work easy. If you think about it this way, you'll write code that's a little more generic than you otherwise would.

Looking at your code specifically, I agree with most of what's already been said, but here is more.
1
2
3
4
5
6
#include <iostream>
#include <iomanip>
#include <windows.h>
using namespace std;

int main(){

What does this program do? How am I (or you in 5 years) supposed to know without having to dig into the code? Write a 1-2 sentence comment that says what it is.

cout << "\033[2J\033[1;1H"; What the heck is that string!!?? I guess it doesn't something to the screen, but what? Does it clear it? Change the color? I have no idea. Again, comments are your friend.
What - you don't speak VT?

\033[2J - clears the entire screen
\033[1;1H - positions the cursor at row 1, column 1 (could have been \033[H )

C++ would not be amiss to dump those into named constants in a #include, maybe added to iostream or something.
Nah, I don't agree. The standard shouldn't contain platform-specific stuff. It shouldn't include VT control sequences for the same reason it shouldn't include the GUIDs for Windows known folders.
Last edited on
I thought the VT was near universal now. If its not, then I agree.
It might be, but that's only the case incidentally. It's still platform-dependent.

Besides, the library doesn't even recognize the concept of a "console" as a generic device. It would be weird for it to declare magic strings that do mysterious things with unknown devices when they're sent over streams that happen to be connected in specific ways.
It would be like the standard mandating inclusion of an HTTP server, but not any kind of networking.
Then what about TVI (Televideo) codes? Wyse codes? Back in the 1980's many non-DEC users used these type of terminals instead. Manufactures made terminals that had emulation modes so you could buy one terminal and set it to use whatever code set was required.
yea, too much to take on.
But if I get back into much console work I may make one for myself :)
Back in the day when I used Pick, within Basic you had the @ construct as part of the print statement. This enabled various special codes (eg @(-1) cleared the screen). There were about 100 of them. Positive numbers related to moving the cursor. Then for each port you specified a terminal type which when the @'s were encountered looked up the @ value in a table and got the required codes for that terminal for that function. If you needed to support a different set of codes for a different terminal that wasn't already supported then all you had to do once was specify the escape codes for each @ function (via a provided TCL command) used/applicable. No changes to any programs were required.
Pages: 12