Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Void Return Type Methods and Mathematical Functions

 
Ken Austin
Ranch Hand
Posts: 39
Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While preparing for an upcoming Coursera course (Introduction to Algorithms) I came across this statement in the text

For example, the main() static method in our programs has a void return type
because its purpose is to produce output. Technically, void methods do not
implement mathematical functions
(and neither does Math.random(), which
takes no arguments but does produce a return value).
-- p. 24 Algorithms (4e), Sedgewick & Wayne

Bold mine.

The part in bold stumped me. Can someone walk me through that statement?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12083
29
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The strict interpretation of a function is that basically, you give it some input (like 90 degrees), and you get some new value out - like 1. For any given input, there is exactly one possible output.

Since a method of type void does not give you back a return value, it does not fit the definition of a mathematical function.
 
Mike Simmons
Ranch Hand
Posts: 3028
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And since Math.random() takes no arguments, and since it gives you different results each time it's called, it's not a function either.
 
Ken Austin
Ranch Hand
Posts: 39
Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, yes. Thank you, both.

I was missing the computer science specific definition of the word "implement."

I thought we were about to get into a deep discussion about design theory.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, more a deep discussion of maths.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic