Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

winforms .Net Regarding use of small methods

I work on developing application using winforms in C#. While developing, I want to use many small methods e.g. resetPerticularCombo(), so the code remains as clean as possible. But the problem is making methods for 3-5 lines of code could lead to too many method calls, I have heard that while compiling Visual Studio 2008 takes care of this thing using code inlining.

My query is that, should I rely on this feature and go ahead with the usage of small helper methods or I should use inlining myself?

like image 431
mohits00691 Avatar asked Jul 13 '11 05:07

mohits00691


2 Answers

You shouldn't worry about having large number of method calls until you've proved that it's a problem. It's very unlikely (IMO) that this will actually cause an issue, and if it gives you more readable code, that's the most important thing.

But test the performance all the time to see whether it's acceptable. Find out where the bottleneck in your code is, whether by profiling or other techniques, and consider micro-optimizing just at the points where it'll make the most difference.

In my experience micro-optimizing at the "use fewer methods" sort of level is almost always pointless compared with higher level changes (e.g. going from a list lookup to a dictionary lookup, etc).

like image 132
Jon Skeet Avatar answered Sep 27 '22 23:09

Jon Skeet


I agree to Jon Skeet.

Concerning Enterprise Applications I can tell you the following

I'm leading a small developer team ( 5 Developers) . We 've an application with about 500k loc.

We always try to find the most particular concern a method should have. So we got a lot of small, and "selfexplaining" methods. As a result we have a many many methods and this never lead to an issue.

Most of the time the bottlenecks are in accessing ressources like SQL Server, Files, etc... Or a lack of asynchronity.

Also i've you have a perfomance you could profile it using ants profilder.

I also like these "rules" of optimization I found sometime ago on the web

FirstRuleOfOptimization - Don't.

SecondRuleOfOptimization - Don't... yet. P

ThirdRuleOfOptimization - ProfileBeforeOptimizing

If your developing a timecritical software (Graphic or driver related) then this things can make the point, but then I wouldn't be sure if .net were the best environment to do that

like image 37
Boas Enkler Avatar answered Sep 27 '22 22:09

Boas Enkler