Reputation
359
Top tag
Next privilege 500 Rep.
Access review queues
Badges
2 8
Impact
~13k people reached

  • 0 posts edited
  • 0 helpful flags
  • 54 votes cast
May
12
comment Functional vs object-oriented style in C#
@valenterry - Sure. If simplified, there's an Element entity with many representations. All these functions return a different representation of an Element. Basically it's a value that might be expressed for instance in different bases (binary/hex/..) based on many options.
May
12
comment Functional vs object-oriented style in C#
@valenterry This is not actually tied to a specific example. The functions could be private too. Currying - I think that is a solution. However I have a concern about it: When I curry all these functions taking the same parameter and keep references to the curried ones (because I'll use them more than once), it is almost equivalent to defining a class with instance methods, just more complex. Do you agree?
May
12
comment Functional vs object-oriented style in C#
@RobertHarvey - That is true but can you elaborate your point?
May
12
comment Functional vs object-oriented style in C#
What is 'ADM' in your example?
May
11
comment Functional vs object-oriented style in C#
I tried to say >1 actually. Yes, I agree that is better.
May
11
comment Functional vs object-oriented style in C#
Welcome and thank you for your help. The reason why I am moving the methods is to make them instance methods and take advantage of the constructor to set the parameter once, so that the methods do not need a parameter.
May
11
comment Functional vs object-oriented style in C#
No, it doesn't change the parameter neither.
May
11
comment Functional vs object-oriented style in C#
When I move the methods, I make them instance methods and set the parameter once in the constructor.
May
11
comment Functional vs object-oriented style in C#
@Ewan I believe I don't have a problem with function bodies. You can assume it doesn't change any variable declared outside its scope.
May
11
comment Functional vs object-oriented style in C#
...If the state object is going to be immutable, that is.
May
11
comment Functional vs object-oriented style in C#
@Ewan Added sample code.
May
11
revised Functional vs object-oriented style in C#
added 551 characters in body
May
11
comment Functional vs object-oriented style in C#
I will eventually need to keep the state somewhere. For example, if the state object has many variables and I just need to update one of them during runtime, I believe I'll have to clone the state with only that variable's value changed.
May
11
comment Functional vs object-oriented style in C#
Not always, but yeah, sometimes :). For example the user updates the parameters and I have to refresh the display accordingly; so I just set properties of calculation object to new values and recalculate. I believe my main concern is performance, not that I measured it, but I'm not experienced enough on whether the whole immutability and required .Clone calls in C# will be ok in terms of speed. But thanks for pointing me in this direction.
May
11
comment Functional vs object-oriented style in C#
@Graham Thanks, I might try that. I believe my mindset is still working more OO-centric than functional but I'll fix that:)
May
11
comment Functional vs object-oriented style in C#
@AndyBursh Yes, I'm also learning F#. Unfortunately I cannot use it in my projects at work since no one else knows it.
May
11
comment Functional vs object-oriented style in C#
@Graham: Lose the benefits => impure functions, need an instance to call the method, etc. Nested static classes => Agreed, I already use them but still cluttered because of the extra parameters in functions. 'string' => Point taken, but I think 'string' is too basic to be an example, for example how many methods take 'DataGridView' as parameter?
May
11
asked Functional vs object-oriented style in C#
Oct
27
awarded  Notable Question
Apr
4
answered Are there flavours of OOP where some or all of the SOLID principles are antithetical to clean code?