How many lines of source code should a function have?
This is a question that I'm really curious about: How many lines do other people write in their functions? For me, it's always very different. To be honest, I like to have several larger functions based on several smaller ones. The larger ones are always around 45 lines long at the most, but I also like to support these larger functions with semi-larger functions (which are around 20 lines long at the most). What's your opinion?
And yes, you old C geeks, I know that I need 1212931 1-line functions because otherwise my program runs 0.0000000000000001 milliseconds slower, but I think that for visual reasons it always becomes very confusing.
(The same applies to files)
This shows very well that you still have no idea what good functions are.
Simplified: A function takes over exactly INTRODUCTION Working step. No more, no less.
The reason for this is not in any milliseconds you’re fabuling about, but is that it makes debugging and waiting possible even after 6-12 months (or longer). If the program doesn’t load a file correctly, then I’m looking for the FileReader used – and not for any 200 line feature named “LadeMalDenGanzeKram”.
However, I also talk about the professional (work) area. Private and a hobby you can of course handle how you are funny. Look at this. https://www.ionos.de/digitalguide/websites/webdevelopment/was-ist-clean-code/ There are some employers or Developer teams worth it.
Very interesting. I’m honest I’m still a young man to work and in internas I always didn’t even have to code xD
I don’t think the first sentence is very nice but what do I expect in a seemingly difficult to understand sakasmus.
For example, updateObjectList(); what a FUnction that is true to be 100 lines long but is well-committed better than: createBaseObjectList(); updateObjectList(); createListElement(); etc pp. Functions, but this is my opinion and I think I would be beaten by my employer, but now I have only 4 years of experience (that is btw no sakasmus)
Trozdem, you could answer the question a little more accurately and tell me how to write your private code or if you start 9/11 2.0 as soon as you see a function longer than 20 lines (sorry for the joke).
Don’t be so mimicful if you’re different from
ensign.
I can do it.
No, I’m too old as if I’d open a barrel again if a boy’s mouth thinks he knows everything better than any other developer before him (no sarcasm). So if someone thinks to present me a method with 200 lines, then I’ll rework it and mention it in the next stand up.
You said you had four years of experience. Now, of course, I don’t know if you’ve only been working for small shops or even in real developer teams. I’m in the latter area and can tell you from this: “Lone ranger” with their super-own code don’t really last long in the industry. Because what you see as a great code is for others (such as me) an interpretation that needs to be revised every time so that others can work with your code. These revisions cost time and money. And if you constantly cost these costs because you want to make yourself more real, instead of holding you to the Coding Guides (reasonable software forgings have something like this), then you have a very quick discussion with your supervisor.
The reason for this is not that no one can suffer from you, but that one in team together working. And that also means that the code is written in a way that is everyone is understandable. Personal Gusto is on the back. For example, in my work, I feel our source formatting somewhat exaggerated. But hey – I’m paid for working with such a code and incomprehensible it isn’t. Only oversized – according to my personal taste.
In the private sector, I have programmed classic spaghetti code quite sooner (last millennium – no sarcasm again) and later the giant functions you gave me were used. After the first few WTF moments in which I was looking for death in my own code, I then started to break down and reduce my methods. I prefer methods that fit on the screen at once and can be viewed directly, without scrolling.
I would have liked to comment on your code example now, but I don’t think that’s what I’m doing. There seem to me ad hoc methods and Getter/Setter thematically mixed. But I’ll try it like this:
There’s one Class ObjectList, that would also include a Getter on Data. If I now want to add an object to the list, this is called with me (you note the big and small words: the small written is an object – not the class!) objectList.Data.add(xxx); Thus, there would be no createListElement() and also no upodateObjectList() (this happens automatically) and the createBaseObjectList() then lies simply in the constructor with its functionality.
I hope I could help so far – even if I’m one of those old C crackers.
Thank you very much for the answer, I find very interesting thanks also for tip 😀
So the “you” is all right, I don’t need to be buried.
There is this saying: “Too many chefs spoil the porridge.” The same problem is with software development in teams. We are in our team:
And we’re just one of three developer teams. Now must GENERAL will be coordinated so that a reasonable software will come out at the end. Difficulties include:
With us, for example, there is also a standard case that no one simply checks such code into the common code base, but that it before always a review of at least one other team member.
Now imagine the case that happened exactly like this:
Our Azubi has written his code more or less “free schnapps”, similar to you described it. So his methods were also quite “thick” and the principle of singular steps in the methods he did not follow.
Now he wanted to check the code and needed a review.
The cryptologist no longer makes full reviews, and it is now too far from the code base. The other senior developer just said, “I’m not doing this” and left the task open. The team leader has held an external training. The front eagle could not make the review because it was a backend change.
So I did the review.
And as expected (he is still Azubi, there is still some puppy protection) his code has not worked. But I couldn’t tell him what place the mistake was. I had to use file names, method names AND Line numbers work – just because the methods were so huge.
Spolier: He has not yet been able to fix his bugs because he himself has difficulty finding himself in his code. He’s about a strong refactoring at the moment.
As an Azubi – unsightly, because he has unnecessarily consumed time. If he had complied with the code guidelines, the problem would have been solved weeks ago. But as paid developer you can’t allow that too often or long.
So what are my ideas for improving the coding?
Otherwise, my most important tip for everything is: GOODS. Never take anything as simple as given, but always ask: “GOODS Do you want me to do it that way? GOODS have these directives been introduced? GOODS is software developed today?” Execution of these topics – the will take you on.
I think I’ll talk a little bit, but no matter.
First, I’m sorry I was really a little unpublished, please apologize.
Second: I liked your example very much : That’s the way I probably would have done it (although after living 1-2 processing steps), I didn’t mean it. I was primarily about making it look smarter to write a (semi) “Spaggetti code” that was more a question, but if I looked at it that was really terribly dazzled because I think (and I say 100% only as a polite advanced programmer) that I find it very unpleasant if the function doesn’t fit on the screen, but what I hate even more But as I said, none of your messages really do what, and that’s just what I can’t understand.
It is true that I like to remove myself from Coding Standards, but I am certainly not one of the one code guide so disregarded that one is not sure whether that has anything to do with programming (I just want to put it right, sry for this stupid comment).
I don’t understand the 5 paragraph when you ignore the quotes at the beginning, but I’ll let it go.
Actually, you’re the little shops and teams, I’ve got half. I used to work in the biggest company in our surroundings, but that was an electronics manufacturer of why I ran around with Arduino. Otherwise there was never something exciting.
But I have probably earned that, no matter, I understand the point very well I have already made the experience even though I am only 4 years in industry, as I said, but I assure you that I have the greatest respect for older developers, I would like to learn a lot from you, but in the communication this unfortunately fails a little. I understand the mindset: “The boy with her cool JavaScript stuff we’ve developed 30 years ago.“, to whom I can agree, but I find the eternal back and forth of both parties quite annoying (while most of them looked at me as the boys). Therefore, I would like to know what you think should change the coding again (as I said it would be interesting).
As you have noticed, I have chosen points in almost all the DIscussion points, which is a good example of what I don’t like to write on this 100 FUnctions, but that’s a stupid argument because I do it myself:D