Jump to content


Check out our Community Blogs

0xFACEB004

Member Since 05 Feb 2013
Offline Last Active Jul 09 2016 08:02 PM
*****

#669286 Nested For Loop [EXAMPLES!]

Posted by 0xFACEB004 on 21 March 2014 - 07:17 PM

What have you tried so far?


  • 1


#668536 Had interview with Google today

Posted by 0xFACEB004 on 24 February 2014 - 08:59 PM

Sorry to hear the news Pally, but glad that you had the opportunity to go through the process. Hopefully what you've learned will help next time.


  • 1


#668433 Hello all!... and a small question :)

Posted by 0xFACEB004 on 20 February 2014 - 11:04 PM

Welcome geronimo!

 

I've had some pretty bad instructors a long the way too (one would answer his cellphone in the middle of his lectures and constantly wax poetic about his time in the Navy...which had absolutely nothing to do with programming), but I've had some good ones as well. Is it normal, maybe? But the good ones really increased my understanding of programming overall, while the bad ones forced me to be resourceful in researching the answers I needed...which is probably a good skill to have as a developer.

 

As well, the experts here at CC are an invaluable resource, and are always willing to help.


  • 1


#667261 Corrupting Wishes Game

Posted by 0xFACEB004 on 12 January 2014 - 07:37 PM

Granted, but you had to move into the heart of ghetto to find such better neighbors -- who were subsequently kill in a drive-by shooting, leaving with you with new NEW neighbors who are much worst than your original neighbors.

 

I wish had read more Faust so that I'd know better than to play this game lol :D


  • 1


#667245 Simple Debugging Techniques for Beginners

Posted by 0xFACEB004 on 11 January 2014 - 08:59 PM

I've wanted to write a tutorial for quite some time now, and I'd planned to cover a topic a bit more advanced (thanks to Evan and BlackRabbit for all of their help on it), but after following some of the "help me!" threads here on CodeCall, as well as chasing down problems in my own code -- I've decided to write a simple beginners guide to figuring out why your program is not doing what it is supposed to do. This tutorial will only address logic errors and won't help with syntax or compile time errors.

 

These techniques should work in any language, so I will be using pseudo-code for my examples.

 

 

OK, let's start with the basics.

 

There are three things that have made my coding life easier when it comes to figuring out why things aren't going as planned:

1. Debugging statements

2. Basic understanding of how the program should flow

3. Breakpoints

 

 

Let's take a look at these one by one:

 

 

Debugging Statements:

 

Debugging statements are simply code that outputs information that you can use to trace what is happening in the program as it runs. This can be something as simple as:

// a program to output the age if the name returned is John


myName = readName() // get the value for name from readName function
age = 32

// here is our debugging statement, which will only be used during debugging.
// after debugging just comment it out.
// outputs the value of the name variable at this point.

// following line is for debugging
print myName 

if myName = "John"
    print age

The above statement will simply tell us the value of the variable 'myName'. By outputting the value at this point, firstly we can be sure that myName has a value (myName may have a value or it may be null at this point, the only way to know for sure is to check), and secondly what that value is. If nothing was outputted from our debugging statement for the variable 'myName', we can assume that something is not working properly in the function that is called to assign myName its value.

 

We can do a similar statement in the readName() function to trace what is happening there, as well. The next piece of code is what our readName() function might look like before adding a debugging statement:

// this function is called to read the name
// and return a string of the name that is read
string readName(){

    nameString = ""
    readInput() // reads the input from some file or other input
    return nameString

}

By examining this code you may be able to see what the problem is right away, but let's pretend that we can't figure out why are not getting the correct output. So, let's add a debugging statement to the function to see what happens when we enter this block of code:

// this function is called to read the name
// and return a string of the name that is read
string readName(){

    // for this part of our debugging we may want to add more than one statement,
    // one upon entering the code block so we know where we are in the code, and one before the
    // return statement to check the value of nameString before it is returned


    nameString = ""


    // the first statement will go here:
    // following code is for debugging
    print "In the readName() function"
    print " nameString variable = " nameString


    readInput() // reads the input from some file or other input


    // and the next debugging statement will be here:
    // following code is for debugging
    print "readInput() has returned"
    print "the value of nameString is now :" nameString
 

    // now return the value
    return nameString
}

If we were to code and run the above, our output would look like this:

In the readName() function
nameString variable = 
readInput() has returned
the value of nameString is now :

From this output we can clearly see that the value for nameString either did not change after readInput() returned or it is an unprintable character that cannot be shown on our screen. Either way this is not what we expected to happen, which brings us to number two:

 

 

Basic Understanding:

 

Basic understanding is simply having a basic idea of what the variables, the conditions that determine the programs flow, and the resulting output should or should not be. We know that nameString should have a value before it is returned, and one way to check our program flow is to hard code a value to see if it is returned like we expect it to.

 

This will change our code like so:

// this function is called to read the name
// and return a string of the name that is read
string readName(){

    // we hard code the value for nameString here
    nameString = "nameString Test1"


    // following code is for debugging
    print "In the readName() function"
    print " nameString variable = " nameString

  
    readInput() // reads the input from some file or other input

    // the value of nameString should change after readInput() is called to get a new value
   
    // following code is for debugging
    print "readInput() has returned"
    print "the value of nameString is now :" nameString
 
    // now return the value
    return nameString
}

Now when we run our code again we get the following output:

In the readName() function
nameString variable = nameString Test1
readInput() has returned
the value of nameString is now : nameString Test1
nameString Test1

As we can see, our hard coded value was outputted from out first debugging statement, and the same value was outputted from our second and third statements as well. This tells us that the value is being returned to the caller as we intended, and expected to happen, but we still don't know why the value of the variable nameString is not changed after readInput() is called...and we expected this variable to have a new value after the call. This is where breakpoints come in.

 

 

Breakpoints:

 

Breakpoints simply allow us to intentionally stop the program, or break it, to examine the variables and conditions at that point in the programs operation. In our above example, we know that the readName() function is called because our hard coded value for nameString was returned and printed out; so we know that that part of our program works as intended. We also know that our variables name and nameString are valid because we were able to print them. But we expected the value for nameString to change after the readInput() function was called and it didn't, so let's find out why!

 

First we'll want to determine where to set the breakpoint. Since we know that readName() is being called but is not changing the value of nameString as we expect, let's set our break point where we enter the readName() function.

 

* I am assuming that you already know how to set breakpoints (as every programmer should), if not, just Google it for your preferred IDE.

// this function is called to read the name
// and return a string of the name that is read
string readName(){ 

•  // we set our breakpoint to stop the program at this point so we can examine the following operations step by step

   nameString = "nameString Test1"


    // following code is for debugging
    print "In the readName() function"
    print " nameString variable = " nameString

  
    readInput() // reads the input from some file or other input

    // the value of nameString should change after readInput() is called to get a new value
   
    // following code is for debugging
    print "readInput() has returned"
    print "the value of nameString is now :" nameString
 
    // now return the value
    return nameString
}

When we run our code again, then the program will pause, allowing us to investigate the value of the variables at this point. We will see that nameString is null at this point since it has not be assigned a value yet, but we expect that. Next, (in Microsoft Visual Studio) we step over (F10) to get to the next statement in the function, which would be:

 nameString = "nameString Test1"

and checking our variables again, we find that the value of nameString has changed, just like we expected it to. So far, so good. We step over (F10) again, which would bring us to our debugging code -- which is not really a concern to us at this point, so we simply step over those two lines of code. But the next line of code IS important to us. It's the MOST important line of the code block regarding what we want to happen! This is where nameString should get its new value but it is not...and when readInput() is stepped over** the nameString variable does not change and still has the same value that we hard coded. Why?

 

** "Step into" (F11) could also be used to follow the code into the readInput() function to see what happens there, but for our purpose we'll just step over readInput() and check the variable changes.

 

 

 

If we go back to our code and examine what happens before and after readInput() is called we find where we hard coded a value for nameString, but what ever value that is returned from readInput() is NOT assigned to any variable! Could this be our problem? Let's make some changes to our code and find out.

// this function is called to read the name
// and return a string of the name that is read
string readName(){ 

•  // we set our breakpoint to stop the program at this point so we can examine the following operations step by step

   nameString = "nameString Test1"


    // following code is for debugging
    print "In the readName() function"
    print " nameString variable = " nameString

    
    // **** we change the following line so that nameString gets the returned value from readInput function and then test again ****
    nameString = readInput() // reads the input from some file or other input

    // the value of nameString should change after readInput() is called to get a new value
   
    // following code is for debugging
    print "readInput() has returned"
    print "the value of nameString is now :" nameString
 
    // now return the value
    return nameString
}

Now when run our code and step through, we see that nameString does indeed change after readInput() is called!

 

And for simplicity, let's assume that the name "John" is returned from readInput(), which would then be assigned to nameString, just we intended, and just as we expected. If we remove out breakpoint and run the code again, this would be output:

In the readName() function
nameString variable = nameString Test1
readInput() has returned
the value of nameString is now : John
John
32

This is exactly the output we expected. So now the only thing left to do is to go through the code and comment out all of our debugging statements so that they don't effect the output of our program. Once this is done, our final output will simply be:

32

and this is exactly what we expected the output to be.

 

 

In conclusion:

 

Some programmers (especially some of the old timers I have had the pleasure of learning from) don't like using debugging statements and say that using them is a waste of time, but for new programmers and/or students trying to work out the logic in their coding assignments, this can be a very valuable resource.

 

For larger projects it may become a bit harder to do, but for this I have taken to using log files -- simply creating a class to output the data from my debugging statements to a file; but it is the same useful information, and I can trace what happened when the code ran. And still using debugging statements to show me what is happening in my code as it is running -- I can see if something is not updating, or conditions are not being met, or variables are not getting the values that I expect them to get.

 

And knowing where something is going wrong in your code plays an invaluable role in finding what the cause of the problem is...and finding a solution to it.

 

 

I hope this tutorial helped you with your debugging. Happy coding!


  • 1


#666871 Hope everyone had a great years end...

Posted by 0xFACEB004 on 29 December 2013 - 11:52 AM

Just wanted to say that I hope all of the wonderful people I have met and interacted with here on CC had a great holiday -- no matter what you celebrate (or don't celebrate), and that you all have a great New Year!

 

You all have definitely contributed to my experience as a programmer! Many thanks and much appreciation for that!


  • 1


#666621 Favorite Programmers

Posted by 0xFACEB004 on 14 December 2013 - 02:43 PM

If I had to admire what people have done in the technical landscape, that would be a different list (again in no order): Alan Turning, Bill Gates, Steve Jobs, Linus Torvalds, The whole GNU project, etc..

 

Can I add Charles Babbage to that list too...just what kind of genius comes up with a contraption to compute using steam?


  • 1


#666618 Favorite Programmers

Posted by 0xFACEB004 on 14 December 2013 - 02:03 PM

And that guy KJGino agreed with you, which makes him guilty too.

 

I was simply agreeing that some of my favorite programmers are are not famous, but are the friendly people here on CodeCall who freely offer their skill and expertise to anyone willing to learn...and I even count you amongst them.

 

 

First, I want to say that I can never understand when someone is down-voted for an opinion. We each have one, and as just an opinion, I see them all as equally valid. And that is just my opinion :D

 

With that being said, my favorite programmers (at least those of fame or great stature) have already been mentioned -- but I, like LKP have some not-so-famous favorites as well -- most of which are on this site. The help and guidance, either directly or indirectly through postings, tutorials, and/or blogs, that Evan, wimDC, BlackRabbit, lespauled, WingedPanther, Yannbane, Pally, Barnsite, Vaielab, LKP, and many others is appreciated much, MUCH more than just a +1 to their rep!

 

Thanks guys and girls for all of your help and inspiration!

 

And I still stand by that.


  • 1


#666597 Favorite Programmers

Posted by 0xFACEB004 on 13 December 2013 - 05:36 PM

First, I want to say that I can never understand when someone is down-voted for an opinion. We each have one, and as just an opinion, I see them all as equally valid. And that is just my opinion :D

 

With that being said, my favorite programmers (at least those of fame or great stature) have already been mentioned -- but I, like LKP have some not-so-famous favorites as well -- most of which are on this site. The help and guidance, either directly or indirectly through postings, tutorials, and/or blogs, that Evan, wimDC, BlackRabbit, lespauled, WingedPanther, Yannbane, Pally, Barnsite, Vaielab, LKP, and many others is appreciated much, MUCH more than just a +1 to their rep!

 

Thanks guys and girls for all of your help and inspiration!


  • 2


#666516 just ask about seo

Posted by 0xFACEB004 on 10 December 2013 - 09:09 PM

Just read this article, and thought that it may add further insight:

 


What Everybody Ought To Know About Google Search Algorithms


  • 1


#666104 just ask about seo

Posted by 0xFACEB004 on 21 November 2013 - 01:56 PM

Optimizing sites to be indexed and ranked by search engines will always be around, but I completely agree with WP about the scammers.


  • 1


#666007 Christmas 2013

Posted by 0xFACEB004 on 19 November 2013 - 01:59 AM

Eat food and ignore everyone (and almost every thing) for a whole week!

 

Oh yeah, and sleep between semesters lol!


  • 2


#666005 [Python] - A very simple Palindrome checker

Posted by 0xFACEB004 on 19 November 2013 - 01:38 AM

KJGino explained that rather well, thank you however he also forgot his cardinal numbers. So the start of the string would be 0 instead of 1.

 

 

Thank you LKP.

 

But my string example was hypothetical, so, as you know, the beginning of the slice does not necessarily have to be at the beginning of the string (position 0); it can be anywhere in the string -- which is also why I specified which positions of the string would be outputted regarding my example.


  • 1


#666001 [Python] - A very simple Palindrome checker

Posted by 0xFACEB004 on 19 November 2013 - 12:06 AM

I understand why it's a variable, but could you explain 'why' then? What would happen if you wrote -2 or any other number? I don't have access to a PC right now, otherwise I would try it out myself.

 

This is one of the few things that I actually remember from Python. It is called Extended Slices. The syntax for it is: [start:end:step]

 

Start is the first character position in the string you are working with, so if you had [1::] it would start with the char at the index 1 position, and since no end point is defined, it would go to the end of the string.

 

If you had [1:4] - it would start with the position 1 and go to the 4th position (but NOT include the 4th position, so in essence 1 through 3).

 

If you include a step, then you could do something like this: [1:4:2] would output every other char in the string, from position 1 to position 4, but not including the char at position 4.

 

To explain what LKP did - she left the beginning and end undefined so that the whole string would be used, and since the step was -1, it iterated through the string in reverse. So, [::-1] would give you the output of the whole string in reverse.

 

See here for more detailed information on Extended Slices.


  • 2


#665994 [Python] - A very simple Palindrome checker

Posted by 0xFACEB004 on 18 November 2013 - 07:17 PM

@OP

This is a nice little trick/exercise, as a result I attempted it in Java, and would be interested to see your one line solution. Here is one that I wrote, however; it is written in Java (however, should easily be translatable)

return isPalindrome = new StringBuilder(stringHere).reverse().toString().equals(stringHere);

Look forward to your response.

 

Your one line is very close, but one minor change is needed for it to work exactly the same way, in case some one decides to try it out:

return isPalindrome = new StringBuilder(stringHere).reverse().toString().equalsIgnoreCase(stringHere);

otherwise it will return false for a word like "Dad" because of capitalization, as I am sure you already know :D


  • 1




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download