Timeline for How to write useful Java programs without using mutable variables
Current License: CC BY-SA 3.0
37 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 16, 2020 at 10:01 | history | edited | CommunityBot |
Commonmark migration
|
|
| Sep 29, 2015 at 15:13 | comment | added | gnat | possible duplicate of How to code in a more functional style in Java? | |
| Mar 19, 2014 at 22:02 | comment | added | kevin cline |
@AndresF: there is no problem in Java writing Iterable<BigInteger> integers(). It won't be purely functional because the Java Iterator class is mutable by definition.
|
|
| Feb 19, 2013 at 0:32 | answer | added | Stephen C | timeline score: 3 | |
| Feb 18, 2013 at 17:37 | answer | added | minopret | timeline score: 2 | |
| Feb 18, 2013 at 3:22 | answer | added | cHao | timeline score: 6 | |
| Feb 16, 2013 at 17:31 | answer | added | Ingo | timeline score: 0 | |
| Feb 15, 2013 at 20:57 | comment | added | Andres F. | @ruakh & MichaelShaw Oops, my sarcasm detector failed :) | |
| Feb 15, 2013 at 20:33 | comment | added | Michael Shaw | @AndresF.: I think ruakh was sarcastically implying that the author of the article didn't know what he was talking about. | |
| Feb 15, 2013 at 20:27 | history | edited | yannis | CC BY-SA 3.0 |
added 214 characters in body
|
| S Feb 15, 2013 at 19:36 | history | suggested | user39685 | CC BY-SA 3.0 |
tried to get the title to focus on the conceptual problem. doesn't look like I pulled it off though :(
|
| Feb 15, 2013 at 19:24 | review | Suggested edits | |||
| S Feb 15, 2013 at 19:36 | |||||
| Feb 15, 2013 at 19:20 | comment | added | S.D. | @MichaelKjörling Language syntax and programming approach debates revolve around this, the demand of the computer, one claims his way to be more elegant, concise, aesthetic etc, for the computer. Actually, its other way around, we require computers to fit around our expression styles. | |
| Feb 15, 2013 at 19:16 | answer | added | wnrph | timeline score: 6 | |
| Feb 15, 2013 at 19:15 | answer | added | Pete Kirkham | timeline score: 3 | |
| Feb 15, 2013 at 19:06 | comment | added | Andres F. | @ruakh Where did you get that idea? Many FP languages have garbage collection. In fact, without explicit memory management, they must implement GC in some form. Or do you suppose they simply run out of memory and crash? :) I wouldn't rely on Uncle Bob's speculations on FP, since he is definitely not an expert ;) | |
| Feb 15, 2013 at 18:59 | comment | added | user |
@User117 Is that 0 to 25 inclusive or exclusive on the lower or upper bounds respectively? Integers only, or fractional values as well? If fractional numbers are included, what stepping? Print to where? Do you mean the square of the number or a square containing the number? Etc etc. :) After all, the hard part of programming often isn't writing the code -- it's translating the vaguely stated requirements into the exactness demanded by the computer.
|
|
| Feb 15, 2013 at 18:09 | answer | added | FrustratedWithFormsDesigner | timeline score: 21 | |
| Feb 15, 2013 at 17:34 | comment | added | S.D. |
That FP vs OOP rant again. can you compile print squares of all numbers from 0 to 25 ? . All programming languages are far from our natural language yet.
|
|
| Feb 15, 2013 at 17:04 | comment | added | ruakh | @thiton: I agree, for the most part, but if you look at the linked article, Uncle Bob really does claim that "if you could peer into the computer’s memory and look at the memory locations used by my program, you’d find that those locations would be initialized as the program first used them, but then they would retain their values, unchanged, throughout the rest of the execution of the program". (Apparently FP doesn't support GC. Who knew?) | |
| Feb 15, 2013 at 16:20 | comment | added | user39685 |
@Blrfl you bring up an excellent point -- recursion must be done carefully even in many (most?) functional languages if you want to avoid memory problems. Some languages, such as Scheme, implement tail-call optimizations which, if the recursive calls meet certain restrictions, allow recursive calls to be made without consuming additional stack space. Clojure, OTOH, encourages the use of the loop/recur macro since it doesn't have TCO -- but the key point is that it still has non-mutating semantics.
|
|
| Feb 15, 2013 at 16:18 | history | reopened | yannis | ||
| Feb 15, 2013 at 16:17 | history | edited | yannis | CC BY-SA 3.0 |
deleted 124 characters in body
|
| Feb 15, 2013 at 16:08 | comment | added | Blrfl |
@thiton: To extend Andres F's point, Clojure's take gets out of using variables explicitly by using recursion. While that is all nice and functional, it does create some form of temporary space to hold the result of the dec it does. I'm not very familiar with Clojure, but I question whether a recursive model for things like that is sustainable for an arbitrarily large collection without running out of stack.
|
|
| Feb 15, 2013 at 16:02 | comment | added | FrustratedWithFormsDesigner | It might be interesting to post to codegolf.stackexchange.com/questions to see what kind of answers you get. | |
| Feb 15, 2013 at 15:11 | history | closed |
gnat Yusubov CommunityBot |
off topic | |
| Feb 15, 2013 at 15:11 | comment | added | Andres F. | @thiton I suggest you learn more about FP languages, but nevertheless, the code snippet doesn't support (or reject) the assertion that "variables" aren't needed (by which I assume you mean "mutable variables", because the other kind is common in FP). The snippet just shows library functions which could have been implemented in Java as well, barring lazy/eager problems which are offtopic here. | |
| Feb 15, 2013 at 15:07 | comment | added | thiton | @AndresF.: Functional programming languages take some pride in not needing variables for most tasks, so I assume that the above functions don't need variables (as opposed to constants) to do their job. | |
| Feb 15, 2013 at 15:06 | answer | added | user39685 | timeline score: 31 | |
| Feb 15, 2013 at 15:04 | comment | added | yannis | That quote is confusing and misleading, there's no magic there, just syntactic sugar. | |
| Feb 15, 2013 at 15:03 | comment | added | Andres F. |
@thiton Disagreed. What Blrfl is saying is that those functions probably use variables written in the same programming language. No need to go low-level here. The snippet is merely using library functions. You can easily write the same code in Java, see: squaresOf(integers()).take(25) (writing those functions is left as an exercise for the reader; the difficulty lies in the infinite set for integers(), but that's a problem for Java because of its eager evaluation, nothing to do with variables)
|
|
| Feb 15, 2013 at 14:52 | comment | added | thiton | @Blrfl: The "behind the scenes" argument kills all language-based debates, since every piece of code is ultimately translated to x86 machine code. x86 code is not object-oriented, not procedural, not functional, not anything, but these categories are valuable tags for programming languages. Look at the language, not the implementation. | |
| Feb 15, 2013 at 14:06 | answer | added | Martin | timeline score: 16 | |
| Feb 15, 2013 at 13:59 | review | Close votes | |||
| Feb 15, 2013 at 15:14 | |||||
| Feb 15, 2013 at 13:47 | comment | added | Blrfl | Your functional example does use variables on the inside, but the language does all of it behind the scenes. You've effectively delegated the unpleasant parts to someone you believe has done it correctly. | |
| Feb 15, 2013 at 13:33 | answer | added | thiton | timeline score: 27 | |
| Feb 15, 2013 at 13:23 | history | asked | minusSeven | CC BY-SA 3.0 |