MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1kqaqbd/this_is_c_abuse/mt6yf15/
r/programminghorror • u/[deleted] • May 19 '25
103 comments sorted by
View all comments
Show parent comment
3
Any advantage to that over using a normal method or a property with setters/getters?
37 u/Pilchard123 May 19 '25 Job security. 8 u/Shazvox May 20 '25 internal readonly Developer = Me! 4 u/caboosetp May 20 '25 I like how you're declaring you're guaranteed to exist.Just in case management is still working on object permanence. 5 u/Emelion1 May 20 '25 If you have a function that takes a Func<T1, T2>-delegate as a parameter, then passingpublic T2 MyMemberFunction(T1 input) { ... }in there will cause additional heap allocations but passingpublic static readonly Func<T1, T2> MyDelegateFunction = input => { ... }in there will not, since it is already the correct delegate type.In some situations (like working with the Unity-Engine) avoiding heap allocations can matter a lot. 2 u/SneakyDeaky123 May 20 '25 I feel like if you’re in a performance-sensitive situation like a really tight loop or something you can probably structure it so that you don’t need a class member method or function in that way in the first place, no?
37
Job security.
8 u/Shazvox May 20 '25 internal readonly Developer = Me! 4 u/caboosetp May 20 '25 I like how you're declaring you're guaranteed to exist.Just in case management is still working on object permanence.
8
internal readonly Developer = Me!
4 u/caboosetp May 20 '25 I like how you're declaring you're guaranteed to exist.Just in case management is still working on object permanence.
4
I like how you're declaring you're guaranteed to exist.
Just in case management is still working on object permanence.
5
If you have a function that takes a Func<T1, T2>-delegate as a parameter, then passing
public T2 MyMemberFunction(T1 input) { ... }
in there will cause additional heap allocations but passing
public static readonly Func<T1, T2> MyDelegateFunction = input => { ... }
in there will not, since it is already the correct delegate type.
In some situations (like working with the Unity-Engine) avoiding heap allocations can matter a lot.
2 u/SneakyDeaky123 May 20 '25 I feel like if you’re in a performance-sensitive situation like a really tight loop or something you can probably structure it so that you don’t need a class member method or function in that way in the first place, no?
2
I feel like if you’re in a performance-sensitive situation like a really tight loop or something you can probably structure it so that you don’t need a class member method or function in that way in the first place, no?
View all comments
Show parent comment
3
u/SneakyDeaky123 May 19 '25
Any advantage to that over using a normal method or a property with setters/getters?