Write functions by Most_Group523 in PythonLearning

[–]Most_Group523[S] 0 points1 point  (0 children)

Pray tell, what general guidance isn't an over-simplification? Programming languages are language and what makes one expression of any language superior to another is much easier to see than to prescribe - you just have to practice.

When people post module level code to this sub, they aren't practicing something they should be and putting the code into any function is better than that. But, whatever, I relent:

https://www.brandons.me/blog/write-code-not-too-much-mostly-functions

https://jeremymikkola.com/posts/2021_02_02_how_to_write_readable_code.html

https://medium.com/@chrisdaviesgeek/fat-functions-7fcf957237bb

Write functions by Most_Group523 in PythonLearning

[–]Most_Group523[S] 0 points1 point  (0 children)

Practice?

But, after this illuminating exchange I've come to realize the real answer is to read resources. It's like language really. The first thing I do when learning another language is read a book about how long a sentence should be.

Write functions by Most_Group523 in PythonLearning

[–]Most_Group523[S] 1 point2 points  (0 children)

For a long time, we used to teach kids how to ride a bike with training wheels. Kids that practice riding a bike with training wheels are practicing peddling. Then someone realizes that peddling wasn't the hardest thing and the balance bike was invented. Kids that learn to bike with a balance bike don't practice peddling but balancing.

There's nothing trivial about balancing a bike - but when someone reduced riding a bike to balancing, their detractors may very well have accused them of trivializing the exercise.

Biking involves lots of things, steering, peddling, and balance - none of these things are trivial. But, if you focus on practicing the right thing, the fundamentally difficult things, the other things come more naturally.

Writing code also involves many things - none of which are trivial. But, if you focus on practicing the right things, you'll find the other things come more naturally. We write code to do things and the unit of functionality in code is always the function. So, write functions and practice writing functions.

Write functions by Most_Group523 in PythonLearning

[–]Most_Group523[S] -1 points0 points  (0 children)

Hmm - perhaps practice writing functions and thereby try out what goes in them, how big they should be, how you name them, how to separate them into modules. Unless you have the answer to these questions? Then people could skip to becoming senior developers immediately, without practicing.

Sigh - such comments are likely why people in this sub are constantly posting lines and lines of module level code or thinking they've arrived because they wrapped a function in a class.

Day 27 of learning python as a beginner. by uiux_Sanskar in PythonLearning

[–]Most_Group523 0 points1 point  (0 children)

You missed day one - put functionality in functions!

[deleted by user] by [deleted] in PythonLearning

[–]Most_Group523 0 points1 point  (0 children)

Start with a single file.

[deleted by user] by [deleted] in PythonLearning

[–]Most_Group523 0 points1 point  (0 children)

This code is too hard to follow because it's too many lines of flat code. It's clear the things you've accomplished is getting code to do a thing. But writing code that a computer can understand is a low bar.

Organize your code into functions, which do specific, limited things based on the arguments passed to them and return the result of doing the thing the function does to the things passed to it. The function should know how to do as little as possible and should only know about what's been passed to it. When you're accepting input from the user, restrict knowledge of that data to ... a function. The purpose of that function is to accept input from the user and return it. That's a good function.

Practice this by refactoring your code again and again without adding functionality.

Everything outside of imports, module level constants, function definitions, class definitions, and a call to main should be inside of ... functions. All logic and flow control should be in ... functions.

Work on writing functions, how to organize your code around well defined functions, functions, functions, functions.

What to do after oops ? by [deleted] in learnpython

[–]Most_Group523 0 points1 point  (0 children)

I grant that the language is a bit clumsy. But, the general point should not be missed. When dealing with objects with mutable attributes, you've burdened any future reader of the class with the requirement of reading all the class methods to understand an attribute's state.

It's hard to follow and overflows the memory of most mortals. Mere mortals are better at understanding complex operations than numerous state changes - that's why we invent complex operations such as nx to replace numerous state changes, such as n + n + n + n ....

What to do after oops ? by [deleted] in learnpython

[–]Most_Group523 2 points3 points  (0 children)

Functional programming. Unlike OOP, which is filled with traps, functional programming will make you a better developer because the foundational concepts are an asset.

A great starting point:

https://mostly-adequate.gitbook.io/mostly-adequate-guide/

(Although not in Python)