Eat. Sleep. Code: The Computer Programming Thread, Ver. 010

Find a new job or request to move to a new project if you can do so inside your current company. A major reason I left my first job out of school had to do with not learning anything new. That and after 5 years my pay had only increased $12k. Nothing is worse than being bored at work. Last week one day our internal network was out all day and I literally could get no work done for 8 hours. Browsing the internet gets boring quickly and you don’t realize that until it’s literally all you can do.

Also the longer you stay at a place not learning anything new and not keeping up with technology, the less marketable you become for future positions. I personally enjoy Java, but only if I’m writing it as a backend and also get to do the front end (and as long as the front end is not Java, that is old tech for front end).

No that’s not what I meant.

Obviously a 5 day crash course isn’t better than spending year or two doing a degree. Like anything you got to put in the hours to become good at something. 5 day crash course covers the basics of programming which is what you’re tested on to get a basic cert. The whole point I was making is there are plenty of alternatives to learning how to code than dropping 10k+

That was a typo, now fixed

There is a huge difference between a person with a college degree in computer science and a person who just knows how to make syntax work though.

Honestly I’ve met a lot of people who didn’t have a degree and come mostly from a business background and I always saved myself trouble by making sure they touched the least amount of things possible. There’s a bizarre wing of programmers who pride themselves on being business people but I don’t think programmers or cs people are actually business people. We don’t wear suits and we have actual skills…

Knowing how to use libraries and stuff isn’t really what programming is. Granted you’ll get far with it but a lot of troubling errors (often security related) can pop up. PHP programmers are notorious for this sort of abusive coding. Knowing the syntax to a language isn’t programming either. Syntax is just there to satisfy the compiler/interpreter. It’s not the same as getting something meaningful done in an intelligent way.

As great as stackoverflow is and I use it pretty much daily, one of the downsides is that it allows people to code by copying/pasting instead of actually understanding it. That’s another symptom of people wanting to get things done as quickly as possible and just getting the task done without fully understanding the possible repercussions.


int main() {
    printf("Hello World!");
    return 0;
}

Wrote it by myself. No copypasta here.

You should have copy/pasted cause that won’t compile.

You forgot to include stdio.h :pensive:

Or maybe you did copy/paste and just forgot that part…

Hmmmm.

I did it without stdio.h

No I will not tell you how.

Taking it to the grave.

Anyone have recommendations for beginner loop practice? Id like to have a solid foundation on them before moving on

If you’re looking for practice, try some of these:

http://www.cplusplus.com/doc/tutorial/control/ <- You’ll have to scan for ones involving loops because they seem to just throw shit of all kinds here.

http://icodecool.blogspot.com/2012/12/c-loops-solved-exercises-practice.html <- Problems and solutions on the same page. Try not to scroll too far to expose the answer.

Or just google for it.

https://www.google.com/search?q=c%2B%2B+beginner+loop+practice&ie=utf-8&oe=utf-8

For loop:

Create an array of the numbers 1-100 and have it output the contents with a comma between each number, but after 10 digits, go to a new line with no comma after 10th digit. so the results would be like:



1,2,3,4,5,6,7,8,9,10
11,12,13,14,15,16,17,18,19,20


etc.

While loop:

Read in an input from a user, like a sentence, and then examine the input character by character and output the input so that each word is on a new line. For example, if the user inputs:



This is the programming thread


You would output



This
is
the
programming
thread


Personally I am not a fan of do/while loops and after being in the industry for 12 years I’ve probably seen them used in the real world less than 10 times if that. They are also the same as while loops except the while logic is at the end of the loop so it always runs once.

EDIT:

A little more advanced for loop one would be something like the following:

Given an input x of a number, create a “triangle” that is x * characters wide and tall.

For example, for the given number 5, the result would be



*
**
***
****
*****


Once you figure that out, then try to make it also go back to width 1 afterwards, which would result in the following for the value 5.



*
**
***
****
*****
****
***
**
*


Make a loop that prints out a multiplication table

One example I’ve seen for do/while was an interesting tactic. You would do it like this



do{

}while(false)


This means it always only executes once, with the benefit that you can do a break at any point and still hit the code at the end. One of my projects has this in there, coded by a previous employee (which was following the standards guide for that specific SDK style). Commonly used like this:



bool16 bSuccess = false;
do{
     if(x < 0)
        break;
     if y < 0)
        break;
 
     z = x + y;
     bSuccess = true;
}while(false);

return bSuccess;


Sure you could probably do something similar without a do/while(false) loop, but I can see the convenience of having a break statement like that in your toolbox

^^ Yeah that logic is completely retarded and gives you absolutely no benefit by using a do/while loop. You could do that without that loop and it reads much easier.



if (x < 0 || Y < 0)
  return false;

z = x + y;
return true;


or if you don’t want to use 2 return statements:



bool16 success = false;

if (x > 0 && y > 0) {
  z = x + y;
  success = true;
}

return success;


And if that is to match a coding standard, that coding standard really should be revamped.

It was pretty old, yeah. Also, your examples don’t actually match up exactly the same. In the first one, theres no “catch all” block of code that always executes when the function is done, it just bails out with an instant return. In the second one, you’re assuming theres just one condition that’s being checked for. If you suddenly have 3 or 4 checks, thats a lot of nested if functions.

Its functionally nothing more than a way to use a restricted goto call, where you can only bail out of a function early.

Your example doesn’t have a “catch all” block of code either. It breaks out of the loop if either of those first 2 conditions are met, then it returns bSuccess. The only “catch all” code you have is the return statement, which only returns bSuccess after the loop. My code handles both conditions where it’s either true or false.

And both of my examples were just examples of your exact code you wrote since you said that was an exact function in your code base. It’s also not a lot of “nested if functions” at all. I actually don’t have any nested if statements in my code. There is 1 if statement in both.

I literally wrote psuedo code off the top of my head to give an example of how it was used, of course if it was that simple in the real applications nobody would write it like that, lol

Well you are the one that said “One of my projects has this in there, coded by a previous employee” then proceeded to write code. I’m not a psychic lol.

But still, my replies to your initial reply still stand true in regards to the logic being the same.

Mandatory assignment: write class in python and test with some basic input.
Code doesn’t run properly in an interactive session. Insists my input is 3 arguments when I’m very clearly only providing 2.
My girlfriend asks me to copy-paste my code and let her run it in an interactive session.
Code runs just fine for her.
???

I think I just had an actual “My code doesn’t work, I have no idea why / My code works, I have no idea why”-moment.

What’s IS? Our school doesn’t have a lot of IS majors here, hell I never even heard of IS until these recent years learning basic level Java stuff.

Think it’s “Information Systems”