thereisareasonwhyweusespacesandpunctuation

Languages like Latin and Ancient Greek didn't always have spaces and punctuation.

Code wasn't always written to be readable.

Both things have changed, for the better

readon👇🪡🧵

thepythoncodingbook.com/2021/10/11/pyt…
#python #100daysofcode #pep8
In the earlier days of computer #programming, there were only a few programmers.

The complexity of computer code was limited primarily by the hardware restrictions on memory and speed of execution.

#codinginthepast #coding
Code was rarely shared and read by others, and teams working on software were small and often consisted of just one person.
Certain habits made sense in those early days and a bit later, too.

Making sure the code was short had some benefits in early computer programs.

So did using short variable names, preferably one or two letters long.
However, as computers became faster and included more memory, programs became more complex.

#Programming languages also evolved to better suit these new, longer, more complex programs.

Teams became larger and collaboration more common.
And the need to maintain code became just as important, if not more important, than writing the code in the first place.
This evolution naturally led to computer code becoming more readable by humans, too.

#Python is one of those “newer” languages and it has readability built into its DNA.
#Python’s syntax makes Python code more similar to plain English than code in most other languages.

But Python goes further than this. It also encourages Python programmers to write neat, readable code. It does this mainly through its style guide, PEP 8 python.org/dev/peps/pep-0…
Not every programmer is entirely on board.

Old habits die hard.

Some programmers still don’t place a high level of importance on how readable computer code is.

And that’s fine.

Defining what’s best when writing code is subjective.
However, the trend seems to be going away from the old style of writing code towards writing code that’s more readable.
Here's a code snippet. Does it make sense? Can you easily understand the code and, importantly, its context? Image
That code snippet wasn't too tricky.

But compare with this one that does exactly the same thing: Image
The only difference is the choice of variable names.

Version 2 needs no comments. Version 1 does.
Here's another example. Version 1 with bad variable name choices and other #PEP8 breaches, too Image
Version 2 (with a bit of overkill, admittedly)

Yes, this is longer, but a lot more readable, a lot less likely to have bugs, and a lot easier to find the bugs if there are any…

…and a lot easier to change in future. Image
To quote PEP 8

"One of @gvanrossum's key insights is that code is read much more often than it is written

The guidelines provided here are intended to improve the readability of code & make it consistent across the wide spectrum of Python code
As PEP 20 says,#Readability counts
Just as punctuation came into written languages to make them more readable, #programming has been undergoing a similar transition in recent years.

In the case of #readability in coding, it’s not the punctuation marks that make the difference but the #CodingStyle.
I hope this thread was sufficiently readable!

Here's the link back to the top in case you want to share with someone…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Stephen Gruppetta

Stephen Gruppetta Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @s_gruppetta_ct

Apr 19
"I'm struggling to understand <topic>.
No matter how much I try, I can't get it"

As I've been getting to know the #Pythonverse on Twitter better in recent weeks, I've seen this common theme recur often from beginners

If this is you, read on…
👇🪡🧵

#Python #codenewbie #coding
It's not just you.

This is the norm, not the exception

There are a number of reasons why this happens.

Here are some of them…
〰️
You may be learning a topic a bit too early.

Some topics need a good understanding of other concepts before you can fully grasp them.

#ObjectOrientedProgramming is one such area. Many beginners try to learn this topic before they've fully mastered the basics…
Read 8 tweets
Apr 18
There are many ways to practise using different data structures in #Python

…not many are as fun as this one!

Here's the step-by-step tutorial to work your way towards writing this animation: thepythoncodingbook.com/2021/10/31/usi…

#100daysofcode #coding #learnPython

1 of 3
In this project, you'll get to use lists, tuples, dictionaries, and sets to set up the grid, colours, and get the balls to bounce and speed across the tiles.

It's fun to write, and fun to watch, too!

2 of 3
If you don't have the time for this but know someone who does, please do share…

#python #coding

3 of 3
Read 4 tweets
Apr 16
Anyone wants a step-by-step tutorial on creating this lunar landing game using #Python's turtle module?

#coding #programming #100daysodcode #learnPython #LearnToCode
This is not a rhetorical question. I haven't written the article yet, so whether I do or not depends on your responses…
Ok, Ok, Ok, you've all convinced me. Now I just need to stop playing the game, and start writing the article.

Easier said than done…

#python #turtle #game #tutorial
Read 4 tweets
Apr 11
Let's fork this thread since people seem to be as fascinated by this topic as I am…

This process happens in nature. Any lens (a camera lens, the eye) 'calculates' the #FourierTransform of the object being imaged.

Read on…
[1/n]

#Fourier #Optics
The Fourier Transform coincides with the plane of the lens. So small lenses cut out the higher spatial frequencies that are furthest from the centre.

Therefore, these higher frequencies do not go through the lens and they're lost…

[2/n]
So when the remaining frequencies are recombined at the image plane (say the back of the camera or the back of the eye), the terms that are needed for the fine detail are not there…

The image is blurred.

This is diffraction.

[3/n]
Read 4 tweets
Apr 11
What's an image made of?

There are many correct answers.

But the most fascinating one is: << sines & cosines >>

Read on if you're intrigued👇🧵🪡

#python #images #fourier
*Any* image can be reconstructed from a series of sinusoidal gratings.

A sinusoidal grating looks like this…

#sinusoidal #grating Sinusoidal grating
It’s called a sinusoidal grating because the grayscale values vary according to the sine function.

If you plot the values along a horizontal line of the grating, you’ll get a plot of a sine function Cross-section of a sinusoidal grating
Read 18 tweets
Apr 10
A quick introduction: I used to be a physicist, which is where I learnt coding.

As a university academic, coding and teaching were both things I enjoyed.

👇🧵🪡
thepythoncodingbook.com/about/
#coding #python
I always felt that explaining abstract and complex concepts in an accessible way was something I'm good at.

My undergrad students agreed…

And now, so do my coding students, young and, er, not so young…

#teaching #learning
Now I spend my time:
—> running @codetoday_
—> teaching coding to kids & adults
—> writing articles and books on #coding and #Python
—> creating and running Python courses and workshops (coming soon…)

You can read my articles on:
º thepythoncodingbook.com
º @realpython
Read 4 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(