Bad form not to use functions in Python?

  • Context: Python 
  • Thread starter Thread starter bigfoot100
  • Start date Start date
  • Tags Tags
    Form Functions Python
Click For Summary
SUMMARY

Using user-defined functions in Python is essential for organizing code effectively, especially as codebases grow. The discussion emphasizes that structuring programs into functions enhances readability and maintainability, regardless of the programming language. While 100 lines of code may not necessitate immediate refactoring, adopting a function-based approach is a hallmark of proficient programming. Clear function definitions and minimal data exchange between them are crucial for optimal code structure.

PREREQUISITES
  • Understanding of Python programming concepts
  • Familiarity with function definitions and scope in Python
  • Knowledge of code organization best practices
  • Basic principles of software maintainability
NEXT STEPS
  • Research Python function definitions and scope management
  • Learn about code refactoring techniques in Python
  • Explore best practices for writing maintainable Python code
  • Investigate the use of Python modules for better code organization
USEFUL FOR

Python developers, software engineers, and anyone looking to improve code organization and maintainability in their programming practices.

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

Similar threads

Replies
3
Views
3K
  • · Replies 10 ·
Replies
10
Views
4K
Replies
6
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 47 ·
2
Replies
47
Views
4K
  • · Replies 25 ·
Replies
25
Views
6K
  • · Replies 9 ·
Replies
9
Views
5K