Software Development and Programming Careers (Official Discussion Thread)

Data-Hawk

I have no strings on me.
Joined
May 6, 2012
Messages
8,419
Reputation
1,985
Daps
16,285
Reppin
Oasis
At the company I work at our coding standards do not permit us to use that operation, so I that's why I wrote it that way.

Cool, it makes sense for clarity. So I can see why.

my company started this recently

for (int i = 0; i <someNum; i++ )
{

}
The opening brace must be under the "for" and never on the same line. I hate the brace being on the same line anyway.

We also started enclosing all loops/conditionals with braces, even one liners

So

//Wrong
if(isTrue)
ComputeSomething

//Right
if(isTrue)
{
ComputeSomething
}

At first I was like :mindblown:, its just one line. But it was explained that you or another coder may one day want to update the code and possibly do something like

if(isTrue)
ComputeSomething
Addon and Compute more logic if true.

So its better to just future proof it and use braces the first time around.
 

keepemup

Banned
Joined
Jun 9, 2012
Messages
4,743
Reputation
-977
Daps
5,349
Been wondering, is C++ still a marketable skill? Or even C?

I feel like in a sense it is, because every prestigious company is gonna have old legacy shyt in their code base
C is absolutely a marketable skill. If you are going to be a software engineer for an embedded systems (One of the highest paying sectors of programming) you will definitely need to know c.

I would say C and C++ can be a very marketable skill, especially if you're going into game programming. It also serves as a distinguishing point from all of the Java and scripting language programmers(Ruby, Javascript, Python, etc.) that are starting to flood the market. Being a competent programmer at C/C++ also possibly hints that you have a deeper understanding of what actually is going on with programming than programmers who typically deal in higher level languages... Assembly is another, that while not something you'll probably find jobs easily in, it is a nice bullet-point to have on your resume because it shows you're serious about your field.

I eventually plan on picking up some assembly eventually, but C++ it is for now and possibly C. Memory management isn't necessary to be functional since a lot of languages are garbage collected, but it is very useful in that you now have some idea of what the computer is doing behind the scenes. For example, I heard of 'references' in Javascript while reading the books, but I didn't really understand what that was all about until I started looking at c++ and dealing with references explicitly. I'm still quite basic in my C++ learning, but it's been quite informative.
C doesn't have a built in memory management hence the danger of creating memory leaks. A memory leak is when one allocates memory without freeing it up again. Very scary and can be the source of great consternation, but good programming practices should help to eliminate this from happening.
 

Data-Hawk

I have no strings on me.
Joined
May 6, 2012
Messages
8,419
Reputation
1,985
Daps
16,285
Reppin
Oasis
C is absolutely a marketable skill. If you are going to be a software engineer for an embedded systems (One of the highest paying sectors of programming) you will definitely need to know c.


C doesn't have a built in memory management hence the danger of creating memory leaks. A memory leak is when one allocates memory without freeing it up again. Very scary and can be the source of great consternation, but good programming practices should help to eliminate this from happening.

@Nomadum ( I got ya PM breh, so i'll get some resources for you , my asthma been killing the past few days :mjcry:)

But to add onto the quoted post, this would be a great time to look up Buffer overflows

http://en.wikipedia.org/wiki/Buffer_overflow

http://www.cprogramming.com/tutorial/secure.html

and just to add on for fun

http://nmap.org/


Damn, now I feel like installing Linux..lol
 
Last edited:

kevm3

follower of Jesus
Supporter
Joined
May 2, 2012
Messages
16,290
Reputation
5,551
Daps
83,478
C is absolutely a marketable skill. If you are going to be a software engineer for an embedded systems (One of the highest paying sectors of programming) you will definitely need to know c.


C doesn't have a built in memory management hence the danger of creating memory leaks. A memory leak is when one allocates memory without freeing it up again. Very scary and can be the source of great consternation, but good programming practices should help to eliminate this from happening.
Yep, no memory management in C or C++, meaning you have to have some idea of what you're doing. Memory management isn't necessary to be a functional C# or Java programmer but it gives you a deeper understanding of some terminologies used in other languages that aren't very well explained if you stick with those languages. For example, books about Javascript might talk about heaps and stacks in passing, but a book in C will give you much deeper insight.

Memory management definitely isn't for the faint of heart, but I think someone who loves programming will definitely want to get that skill under their belt.
 

kevm3

follower of Jesus
Supporter
Joined
May 2, 2012
Messages
16,290
Reputation
5,551
Daps
83,478
I much prefer the braces to be on a different line, but most of the programming books I saw had them on the same line... Well oddly enough, it depended on the language of the programming books I read. C/C++ and C# typically had them braces on a separate line, and Javascript and I believe Java had the brace on the same line. Putting the brace on a separate line makes it much easier to find which one matches up to which IMO.
 

kevm3

follower of Jesus
Supporter
Joined
May 2, 2012
Messages
16,290
Reputation
5,551
Daps
83,478
Would anyone else like to suggest the next problem? Let's keep it basic at first but progressively ramp up the difficulty so that the beginners can get in on this too.
 

Type Username Here

Not a new member
Joined
Apr 30, 2012
Messages
16,368
Reputation
2,385
Daps
32,640
Reppin
humans
Would anyone else like to suggest the next problem? Let's keep it basic at first but progressively ramp up the difficulty so that the beginners can get in on this too.


Write a function to determine if a number is even without using multiplication, division or modulo (*, /, %). Return true if it is even, false if not. For simplicity, it has to be a non-negative integer input into the function, i.e.:

int num= 987;
result = isEven( num);

And then print the result
 

Data-Hawk

I have no strings on me.
Joined
May 6, 2012
Messages
8,419
Reputation
1,985
Daps
16,285
Reppin
Oasis
Write a function to determine if a number is even without using multiplication, division or modulo (*, /, %). Return true if it is even, false if not. For simplicity, it has to be a non-negative integer input into the function, i.e.:

int num= 987;
result = isEven( num);

And then print the result


On my iPhone but I'll take a stab at it


Code:
Bool result = false;
Int num = 987;

result = isEven(num);
Console.writeline(result);

Static bool isEven( int num)
{

   Bool IsEven = False;

   For( int i = 0; i <= num ; i += 2 )
       If ( i == num )  IsEven = true;
          
    Return IsEven
}
 
Last edited:

keepemup

Banned
Joined
Jun 9, 2012
Messages
4,743
Reputation
-977
Daps
5,349
Write a function to determine if a number is even without using multiplication, division or modulo (*, /, %). Return true if it is even, false if not. For simplicity, it has to be a non-negative integer input into the function, i.e.:

int num= 987;
result = isEven( num);

And then print the result
Code:
#include <iostream>
#include <string>

using namespace std;

string isEven(int input);

int main()
{
    int input;
  
    cout <<"Enter a positive integer. ";
  
    cin>>input;
  
    cout <<"The number " <<input<<" is "<< isEven(input);

    return 0;
}

string isEven(int input)
{
    int mask = 0x01;
    string result = "even";
  
    if((input & mask) == mask)
    {
        result = "odd";
    }
  
    return result;
}
 

kevm3

follower of Jesus
Supporter
Joined
May 2, 2012
Messages
16,290
Reputation
5,551
Daps
83,478
Here's my solution in Javascript:
Code:
function Even(num)
{
  console.log("\n");
  // convert number to a string
  a = num.toString();
  console.log(a);
   
  //use the split method to put the string
  //in an array and break apart each digit
  a = a.split('');
  console.log(a);
   
  //extract the last digit
  a = a[a.length-1];
  console.log(a);
   
  //convert back to a number
  a = Number(a);
   
  //verify that it is a number
  console.log(typeof(a));
   
  //test if number is even or odd
  if(a === 2 || a === 4 || a === 6 || a === 8 || a === 0)
  {
  console.log("even");
  return true;
  }
  else
  {
  console.log("odd");
  return false;
  }
}

// run test cases
Even(21);  
Even(22);  
Even(23);  
Even(24);  
Even(25);


You can paste it and verify that it works here:
http://labs.codecademy.com/#:workspace

Explanation of the solution: You only need the last digit of a number to determine if it is even or odd so I converted the number to a string and then used a Javascript string method named split that allows you to split the characters and returns the result in an array. I then extracted the last digit in string format and converted it back to a number. Finally, I tested whether the number was even or odd. I left the 'console.logs' in so that you can visually see the progression of this function.
 

kevm3

follower of Jesus
Supporter
Joined
May 2, 2012
Messages
16,290
Reputation
5,551
Daps
83,478
Here is a refactored version without comments and log statements and with input checking to verify that the input is a number. This version is made to be as terse as possible.
Code:
function Even(num)
{
  if(typeof(num) === "number")
  {
  if(num< 0) { num *= -1; }
  a = num.toString().split('');
  a = Number(a[a.length-1]);
  return (a === 2 || a === 4 || a === 6 || a === 8 || a === 0)? true : false;
  }
  else
  {
  throw "That is not a valid number";
  }
}

Here is a visual version on codepen
http://codepen.io/kevm3/full/VYxGNR/
 
Last edited:

kevm3

follower of Jesus
Supporter
Joined
May 2, 2012
Messages
16,290
Reputation
5,551
Daps
83,478
Thanks for the participation everyone. If you have time, please right an explanation for your solution so that we can increase the level of understanding, especially amongst the newer coders.
 
Top