August 13th, 2014, 04:45 PM
Code Cutting Help
I am working on a simple tkinter game that contains numerous occurrences of duplicate code.
Simply put, I can significantly cut down on the total lines of code that my program has by creating
18 additional functions for these sections.
The question can be summed up as:
Is increased functions calls a productive alternative for less lines of code?
Is this a good idea in (A) making my code faster, (B) making my code more efficient, (C) Making
my code more flexible to modifications, or (D) simply a good practice to keep because game
development employers simply like to see less lines of code?
Anything you can provide would be appreciated, such as personal experience, or topics/subjects
that you can refer me to study up on, thanks.
By the way, I am using python.
August 19th, 2014, 02:15 PM
Re: Code Cutting Help
A and B are related, if not the same thing. To determine this, one should measure, e.g., run the alternative versions of the code with typical input on typical hardware repeatedly to obtain timings that are averaged, then compare. The difference may well be negligible, or may be significant yet both may lie within the timing requirements.
Originally Posted by game_guru
A key difference comes for C: functions should do one thing and do it well, so it is generally a good idea to break down a long function into smaller functions that solve their own sub-problems. There is also the Don't Repeat Yourself (DRY) principle, with which you would look for (and sometimes anticipate) repetition in code and design and eliminate it.
D is irrelevant. Yes, if you can write less code to achieve the same task without sacrificing clarity, efficiency, etc, by all means do so, but "lines of code" is a poor metric for judging software.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.