Code Cutting Help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Code Cutting Help

  1. #1
    Join Date
    Aug 2014
    Posts
    1

    Question 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,276

    Re: Code Cutting Help

    Quote Originally Posted by game_guru
    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?
    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.

    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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center