Programming I VB.NET

Miscellaneous. No spam or advertisements, constructive discussion encouraged.
User avatar
Dux_Tell31
Midshipman
Midshipman
Posts:100
Joined:Thu Dec 06, 2012 12:22 pm
Affiliation:Tellrim
IGN:tell31
Re: Programming I VB.NET

Post by Dux_Tell31 » Thu Feb 21, 2013 5:38 pm

fr0stbyte124 wrote: Why do you need to know Hungarian notation?
Most likely because she needs a way to grade the classes program writing tests in a quick and efficient way. Let me give an example.
int is the prefix for Integer, dbl is the prefix for Double, lbl is the prefix for the module Lable, txt is the prefix for the Textbox module,
This is the symbol for a comment: '

Code: Select all

Main Class 
   'Declare
   Dim intExample As Integer
   Dim dblAsnwer As Double
   'Input
   intExample = Convert.Int32(txtUserInput.Text)
   'Calculate
   dblAsnwer = intExample * intExample 
   'Output
   lblOutput.Text = dblAsnwer
End Class
Now what if the different Variables and Modules where named completely random things, or in ABC order. This makes it very difficult for other programmers to read the code.

Code: Select all

Main Class 
   'Declare
   Dim i As Integer
   Dim a As Double
   'Input
   i = Convert.Int32(u.Text)
   'Calculate
   a = i * i
   'Output
   o.Text = a
End Class
As you can see it's significantly harder to understand what is going on in the Program in the second example in comparison to the first. Does that explain it?

Also we're learning to debug programs in class now. So do you have any programs I can try my skills against?
"This is Minecraft, sir. We don't make physics, we ruin them." -Fr0stbyte124
"We are made of the elements out in space, in essense we are the universe discovering itself" -Neil Degrasse Tyson

Avenger_7
Ensign
Ensign
Posts:262
Joined:Sun Dec 09, 2012 11:39 pm
IGN:Avenger_7
Location:Canada

Re: Programming I VB.NET

Post by Avenger_7 » Fri Feb 22, 2013 12:22 am

The second example looks like much better code...
Image

User avatar
fr0stbyte124
Developer
Posts:727
Joined:Fri Dec 07, 2012 3:39 am
Affiliation:Aye-Aye

Re: Programming I VB.NET

Post by fr0stbyte124 » Fri Feb 22, 2013 2:41 am

Yeah, if your variables are used in one place and never again, use your judgement as to whether you need to dress up the name. Using i,j, and k for counters are very, very common, for instance. In your case I would probably make the variables ex and ans. It is also usually unnecessary to label basic variables with their datatype, and usually only serves to make it less readable. Leave the type on the form controls as much as possible, though. Lastly, there was no reason to store the answer to a double, as integer multiplication always results in an integer. If you are worried that the square of your integer will exceed 2 billion, store the result to a long, not a double. Floating point variables can have their precision drop below 1 without alerting you, so they should normally be avoided in integer math.

User avatar
Dux_Tell31
Midshipman
Midshipman
Posts:100
Joined:Thu Dec 06, 2012 12:22 pm
Affiliation:Tellrim
IGN:tell31

Re: Programming I VB.NET

Post by Dux_Tell31 » Fri Feb 22, 2013 10:07 pm

Avenger_7 wrote:The second example looks like much better code...
That is a matter of opinion.
fr0stbyte124 wrote:Yeah, if your variables are used in one place and never again, use your judgement as to whether you need to dress up the name. Using i,j, and k for counters are very, very common, for instance. In your case I would probably make the variables ex and ans. It is also usually unnecessary to label basic variables with their datatype, and usually only serves to make it less readable. Leave the type on the form controls as much as possible, though. Lastly, there was no reason to store the answer to a double, as integer multiplication always results in an integer. If you are worried that the square of your integer will exceed 2 billion, store the result to a long, not a double. Floating point variables can have their precision drop below 1 without alerting you, so they should normally be avoided in integer math.
By "forum controls" were you referring to the TextBoxes and Label? Also, your completely correct when you pointed out that having the double is bad programing. Captain Hindsight never fails!
Thanks for the input. :D
"This is Minecraft, sir. We don't make physics, we ruin them." -Fr0stbyte124
"We are made of the elements out in space, in essense we are the universe discovering itself" -Neil Degrasse Tyson

User avatar
fr0stbyte124
Developer
Posts:727
Joined:Fri Dec 07, 2012 3:39 am
Affiliation:Aye-Aye

Re: Programming I VB.NET

Post by fr0stbyte124 » Sat Feb 23, 2013 1:07 am

I said form control, and yes, it is those things.

And even though long is better than double for integer math, it's worth acknowledging that doubles can get to ±4.5 quadrillion before suffering any errors at integer precision, so it can still handle quite large integer math.
A single-precision float, on the other hand, can only get to about ±8.3 million before losing precision, so do be really careful about using that one for large numbers.

Post Reply