Timeline for Calculating Fibonacci sequence in several different ways
Current License: CC BY-SA 4.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 22, 2019 at 18:12 | comment | added | user73941 | @JsonDork: If a method or function has no side effects and its result is only dependent on its argument (produce the same result for the same arguments when called more than once), it may be candidate as a static method - in functional programming it's called a pure function. | |
| Jul 22, 2019 at 16:54 | vote | accept | JsonDork | ||
| Jul 22, 2019 at 16:53 | comment | added | JsonDork | Hey @HenrikHansen, great answer! Especially with the delegate, combining that one with the benchmark should really improve my tests! The one thing i'm unsure about is the static one, I honestly don't understand when it's best to use static and when it's best to use instances. Could you explain further why static or maybe you got a good link to read regarding this? Thanks! | |
| Jul 22, 2019 at 15:21 | comment | added | dfhwze | I would also agree the chosen algorithm should end up as Math.Fibonacci or something like that. For the sake of comparing several methods, I would use an interface (for this trivial domain). So yes, in production code, I agree with the static function in a Math library. | |
| Jul 22, 2019 at 15:18 | comment | added | user73941 | @dfhwze: Normally I agree in that, but I regard the Fibonacci method just as another Math function for which it would be tedious if you would have to instantiate a Math object each time you need one of its methods (Sqrt(), Pow(), etc.) - You could of course have a global Math instance hanging around, but that is "ugly" IMO. | |
| Jul 22, 2019 at 15:10 | comment | added | dfhwze | This is the whole functional vs interface approach dilemma. You would opt for static classes and executing them with Func. I would favor an interface and instances rather than static classes. | |
| Jul 22, 2019 at 15:10 | history | edited | user73941 | CC BY-SA 4.0 | added 1 character in body |
| Jul 22, 2019 at 15:04 | history | answered | user73941 | CC BY-SA 4.0 |