Python Bad form not to use functions in Python?

AI Thread Summary
Organizing code into functions is essential for effective programming, regardless of the language used, including Python. While having a 100-line codebase may not seem extensive, structuring it into well-defined functions enhances clarity and maintainability. Functions should perform specific tasks and minimize data exchange, allowing for better organization and understanding of the program's overall structure. This practice not only aids in readability but also helps in managing complexity as the codebase grows. It's important to follow good programming practices, but programmers should also trust their instincts about what works best for their specific situation.
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...
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top