A function call for a small method will be used for memory or not ... in C #

I have one question. Rather than writing a large method (including a lot of business logic), I preferred to split this method up into small methods and call them one method because it looks so neat and easy to maintain to me. But my team leader said, "Don't write small methods and call them in one, because it consumes more memory while you call small methods." Is this correct ?

Please suggest what should I do in this case? and thanks again for your precious time

+3


source to share


2 answers


There are many factors here. More context for your project will require some kind of rigorous inference.

In general though, C #, VB, and managed languages ​​in general were designed to prioritize developer productivity over performance. In this light, concern about method call memory consumption seems dubious.



Also, IL-based languages ​​(C #, VB, ...) use JIT, which compiles intermediate code for processor-specific assembly at runtime. JIT is a method. The larger the method, the fewer JIT optimizations. Therefore, a large method can give worse performance than many small methods that do the same job. In addition, JIT can also do an optimization called inline where a small method code is generated inside its caller, completely canceling the function call.

The function call takes up very little memory with C # / VB conditions. Unless you are working in a very limited environment (such as an embedded one), such optimization doesn't really make sense, especially if no reasonable arguments support it.

+3


source


Both of you are wrong.

OOP is built on the concept of separation and conquest, so you should split your method into smaller methods for the sake of reuse and maintainability.



About memory consumption, I don't think it will consume more memory, but it can happen when creating methods for every small task.

So, yes, split them into small methods, only if necessary, regarding resources and exchange of variables.

+1


source







All Articles