2 Replies - 198 Views - Last Post: 12 August 2014 - 10:59 PM Rate Topic: -----

#1 dreamlessness  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 29-June 14

Pointers On Code Cutting

Posted 12 August 2014 - 05:13 PM

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, © 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.

P.S. I am using the mainloop() structure for python tkinter. All my functions are contained in 1 class.(if that provides an insight)

Is This A Good Question/Topic? 0
  • +

Replies To: Pointers On Code Cutting

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3479
  • View blog
  • Posts: 11,826
  • Joined: 12-December 12

Re: Pointers On Code Cutting

Posted 12 August 2014 - 06:04 PM

Repeated sections of code belong in functions. The fact that this might reduce the number of lines of code is a side-affect, it should not be an aim.

The difference in execution speed, because of the function-calls, is, in nearly all cases, negligible.

Of more concern to me is the fact that you anticipate it requiring 18 new functions, for a simple game. This would make me consider re-factoring, and possibly re-writing, the application.

Quote

All my functions are contained in 1 class.(if that provides an insight)

This also makes me think this way. I'll guess that you also realise that your single class is doing too much.

So.. none of A,B,C or D. It is simply that repeated sections of code belong in functions.
Was This Post Helpful? 1
  • +
  • -

#3 jerryunsigned  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 8
  • Joined: 18-July 14

Re: Pointers On Code Cutting

Posted 12 August 2014 - 10:59 PM

Yes, it is good that you are looking at functions as a way to cut down your lines of code.

It is good style to put any repeated code in a function. This will definitely make your code a lot more flexible to modification because if you want to make a change, you will have much fewer repeated lines to rewrite.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1