Bad form not to use functions in Python?

  • Context: Python 
  • Thread starter Thread starter bigfoot100
  • Start date Start date
  • Tags Tags
    Form Functions Python
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
bigfoot100
Messages
4
Reaction score
0
I have a 100 line code which is liable to increase, so far I have not included any user defined functions, so it is one stream of code. In c I was taught to put everything I could into functions, is this the case in python i.e. would I be frowned upon for not using functions?

Many thanks.
 
Physics news on Phys.org
Organizing a non-trivial program into a collection of functions that are named clearly, perform well-defined tasks and exchange the smallest amount of data necessary to perform those tasks while keeping other data "local" to each function, is a hallmark of an effective programmer, regardless of the language. For years, I've aimed for this goal in programming in Fortran, Pascal, C++ and Perl, and I see no reason why Python should be any different.
 
Do whatever you think is right. There are obviously some good programming practices but don't blindly follow rules because you feel that's what you should be doing...

100 lines of code is not exactly huge. If there's no code to refactor and it makes sense to you, I'm sure it's fine...

Even without code reuse, breaking up a program into smaller functions called from a main routine (in Python, that'll just be the part of your program that actually executes things rather than just declarations) will allow you to see the overall structure of your program in one small(er) location. You can examine individual functions to see more implementation details. Of course, this works best if your functions have well defined roles and you'll want to keep their interactions as simple as possible, etc... but all this should come naturally to you as you code more...

Just do what you think works best and it should all work out, eventually...
...and yes, this is true regardless of language...