Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 19th, 2013, 05:32 PM
Authorized User
Points: 179, Level: 3
Points: 179, Level: 3 Points: 179, Level: 3 Points: 179, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Lesson 20, Try It

Ok, I copied the code and it works.

But the Calculate button runs the method "FindMinimumMaximumAverage" to find "smallest, largest and average" values.

However, the method uses the terms "minimum, maximum and average".

So how does the calculation know that the value "minimum" is what it is calling "smallest" and the value "maximum" is what it is calling "largest" ??

Or is it just because that is the order it is outputted from the method? ( least number first, biggest number second, average third)
  #2 (permalink)  
Old June 20th, 2013, 09:40 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Quote:
Or is it just because that is the order it is outputted from the method? ( least number first, biggest number second, average third)
That's basically it. The method has its own names for its first, second, third, etc. parameters. It also knows their data types so, for example, you cannot pass a string instead of a float for a particular parameter.

But it doesn't matter if the names in the calling code don't match the names used inside the method. In fact, sometimes the calling code might pass the result of an expression like 10 * 3 into a method as an argument. In that case, the calling code doesn't have a name for the value (30 in this example).
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #3 (permalink)  
Old June 20th, 2013, 12:29 PM
Authorized User
Points: 179, Level: 3
Points: 179, Level: 3 Points: 179, Level: 3 Points: 179, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Visual Studio complains and refuses to run if I type a comma instead of semicolon, but will run a whole method and then say "here's the values, call them whatever you like" ??

Ridiculous.
  #4 (permalink)  
Old June 20th, 2013, 12:45 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Two issues here.

First remember that the computer isn't really smart. It's actually a bit stupider than a toaster. A toaster can inherently make toast but a computer can't do anything unless you program it. So programs like compilers are are easily confused by things like misplaced aemi-colons.

The computer gives the illusion of intelligence but it's really quote stupid.

Second, suppose you write a method that performs some calculation, for example, finds an average. You might want to use that method in many places. It would not make sense for me to force you to give your variables the same name in every place. In one place you might want to calculate average salaries, in another average ages, and in a third average number or pieces of paper used. If I force you to name all of those values "value," it would make your code much harder to read and debug.

So you name your values whatever you want. Inside the method, I use a name that makes sense within the method.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #5 (permalink)  
Old June 20th, 2013, 02:08 PM
Authorized User
Points: 179, Level: 3
Points: 179, Level: 3 Points: 179, Level: 3 Points: 179, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just watched the video for this Lesson, and I'm not sure if I'm less confused than before, or more.

In the video, (at about 6 min, 49 secs) you define :

smallest = minimum;
largest = maximum;

Which is what I originally was asking about. Those two lines are not shown in the Try It, but you took time to define them in the video.

What makes it more confusing is that you name your method

"FindMinimumMaximumAverage"

and your Comments say:

"//Find the minimum, maximum and average"

but then set it to output not "minimum, maximum, average" but "smallest, largest, average".

If the method is named FindMinimumMaximumAverage why does it not output minimum, maximum, average?

Then you would not have to redefine smallest as minimum and largest as maximum.

And your Comment line would make sense.

Finally, at the end of the video, you replace all instances of "minimum" with "smallest" and all instances of "maximum" with "largest", and deleted the two definitions that you had just made!

Why not name the method:

FindMinimumMaximumAverage(values, out minimum, out maximum, out average);

??

Then

//Display the results

would be:

minimumTextBox.Text = minimum.ToString();

etc.



Most confusing.
  #6 (permalink)  
Old June 20th, 2013, 02:28 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

I think one of the things I was trying to get at with this example is the difference between the names used by the calling code and the parameter names used by the method. Yes, you could give them the same names, but ou don't have to.

If someone else was writing the routine, they might use names different from yours but it wouldn't stop you.

But you can certainly make them the same if you like.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #7 (permalink)  
Old June 21st, 2013, 03:20 PM
Authorized User
Points: 179, Level: 3
Points: 179, Level: 3 Points: 179, Level: 3 Points: 179, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That makes sense, but recallss to mind what you said earlier in this thread, that computers are basically stupid.

You're right, of course, which brings us back to my original question: How does the computer (as the Solution is presented in the book) know that minimum = smallest and maximum = largest?

In your video, you make those two definitions, but in the book you do not.

I copied the code directly from the book, and it worked, but I still cannot figure out why.

The computer is too dumb to know that smallest = minimum, so how did it figure it out?

Just because of the order in which the results were returned by the method?

Anyway, the note in the gray box on the top of page 249 may be a better solution.
  #8 (permalink)  
Old June 21st, 2013, 03:24 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

You said it in your original post. It knows by the ordering of the parameters.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 20 Page 152 ThePromise86 BOOK: Knight's 24-Hour Trainer: Microsoft SQL Server 2008 Integration Services 1 January 26th, 2014 10:02 AM
Chapter 20 Clever BOOK: Professional Application Lifecycle Management with Visual Studio 2010 2 January 9th, 2013 07:39 AM
LEsson 20 page 264 willyb BOOK: PHP and MySQL 24-Hour Trainer 2 October 23rd, 2012 02:58 AM
Chapter 20 masegui JSP Basics 0 April 1st, 2004 07:54 AM



All times are GMT -4. The time now is 09:45 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.