Show more

At the start of the program, if you use a word that’s in the red booklet, Monty will know what to do.

keywords like while, built-in functions like print, these are the things in this booklet.

When you create a variable, such as:

day = "Monday"

Monty gets an empty cardboard box, puts the string "Monday" inside the box and puts a label on the outside of the box which says day

Monty puts this box on a shelf in the Main Room

From now on, if you write day in your program, when Monty looks around the room he’ll find a box labelled day and he’ll get its contents—the string "Monday"

/2

Show thread

Understanding Functions using the “Function Room” narrative

I use narratives to learn stuff… and to teach, too

What’s a narrative? It’s a way of connecting events or facts in a form of a story

But I promised to talk about The Function Room

so read on…

My mental image of a computer program is that of a small creature working in a room.

When you start writing a program, the Main Room is empty except for some shelves and a small red booklet called “built-in”

Monty — that’s the name of the little creature doing all the hard work — will look around the room whenever you use any name.

more in the next toot

/1

Here's a post with #python in the hashtags so I can connect with more Python people. ;)

Hey everyone. I made it over here on Fosstodon. Happy to be here with you. ;)

I've released Textual version 0.4.0, which now has smoother animation!

See the blog post for details...

textual.textualize.io/blog/202

In case you want to go back to Day 1 of this series on Intermediate Python functions, here’s the link: qoto.org/@s_gruppetta/10930187

Show thread

Summary: positional arguments and named (keyword) arguments

In summary, arguments can be positional arguments or named (keyword) arguments

When using positional arguments, the arguments are matched to parameter names depending on their position

Named (keyword) arguments include the parameter name in the function call

Tomorrow, we’ll look at optional arguments which have a default value…

/7

Show thread

– 5 –

greet_person(number=10, person="Stephen”)

Since you’re using these arguments as named arguments, you no longer need to stick to the order in which they’re defined in the function signature

Python no longer uses position to assign the arguments to the parameter names. This is particularly useful in functions which can take many parameters

In this example, the programmer calling the greet_person() function has a choice on whether to use positional arguments, named arguments, or a mixture of both (as long as the positional arguments come before the named ones)

There are ways in which the programmer who defines the function can force the user to use positional-only or keyword-only arguments

But we’ll leave that discussion for another day…

/6

Show thread

– 4 –

greet_person(person="Stephen", number=10)

In this case, you’ve used both arguments as named or keyword arguments. You’re no longer relying on the position of the arguments. What matters now is the keyword you use when calling the function.

This leads us nicely to number 5…

/5

Show thread

– 3 –

greet_person(person="Stephen", 10)

This seems identical to the case in the second example, but we come across one of the rules when using positional and keyword parameters

See the description of the SyntaxError. It says positional argument follows keyword argument

When using a mixture of positional and keyword arguments, the positional arguments must come first

And this makes perfect sense, since Python is relying on the position of these arguments within the function call to know which parameter name to assign them to

/4

Show thread

– 2 –

greet_person("Ishaan", number=3)

In the second call, the first argument, "Ishaan", is a positional argument as in the first example

However, the second argument is a named argument or a keyword argument

The argument is matched to the parameter by naming it. You’re using the parameter name with an equals before the argument in the function call

Therefore, in this second example, you have one positional argument and one keyword (or named) argument

/3

Show thread

Let’s look at all five function calls in this example:

– 1 –

greet_person("Elizabeth", 5)

This is the most commonly used function call. The arguments are positional arguments

This means that the values "Elizabeth" and 5 are matched to the parameter names person and number depending on the their position in the function call

The first argument is assigned to the first parameter; the second argument to the second parameter…

/2

Show thread

Day 2 of diving into Python functions — today we’ll look at:

positional arguments
named (or keyword) arguments

I don’t have a preference on which term to use for the latter!

Here’s a simple function – see attached image

—> Which of the five function calls will not work?


While you think about the answer, you can refresh your memory about the terms with yesterdays toot thread!

The parameters in the code above are person and number

The arguments are the strings with names and the integers used in the function calls

/1

Back to dark and light modes.

For someone with high higher-order aberrations (like me), dark mode pushes the pupil size well above the ideal pupil size, therefore vision is worse.

This will not be the case for everyone, of course.

But, dark mode is not for everyone…

If, like me, you prefer light mode, ignore all those who snigger because “pros use dark mode”

/6

Show thread

So, in the human eye, there is an optimum pupil size. If the pupil is very small, diffraction leads to lower resolution…

If the pupil is too large, higher-order aberrations lead to lower resolution.

The sweet spot varies from person to person (it’s roughly around 3-5mm — the pupil typically can vary between 2-8mm in an average eye)

/5

Show thread

How about diffraction?

Diffraction is something completely different… It’s a fundamental optical phenomenon

All optical systems suffer from this, even ones that have no aberrations (imperfections)

Small pupils lead to more diffraction which reduces resolution.

Large pupils have less diffraction and therefore have less of an effect on resolution.

This is why telescopes have large diameters and professional photographers have lenses with larger diameters.

/4

Show thread

Every eye has aberrations, or imperfections…

…and these are not just the ones we correct using glasses or contact lenses.

Those are just the main ones.

The others are called higher-order aberrations.

The larger the pupil of the eye, the more higher-order aberrations there are.

Therefore, in bright lights, when the pupils are small, there aren’t many higher order aberrations…

But when the light levels are low and the pupils large, there are significantly more.

Everyone has higher-order aberrations, but not everyone has the same amount.

So this is worse for some people.

I happen to know that I have reasonably high higher-order aberrations (How do I know this: from my previous work as a scientist when I often measured these)

More aberrations = lower resolution and lower contrast = poorer vision.

/3

Show thread

I used PyCharm’s Darcula and IntelliJ Light themes on a 27” screen — PyCharm was in full screen mode. iMac was on 75% brightness (usual setting)

I stood in my normal position—arm’s length from screen—and looked at the middle of the screen…

Here’s my eye pupil as I switch from dark mode to light mode

Video quality not great (don’t view in full screen!!)—but this is just a rough experiment, so it will do nicely

And you can see stills, with a very rough estimate of the relative pupil sizes, in the first toot…

On the right you’ll see the small pupil from the light mode scenario shown in red and superimposed on the black “dark mode” pupil

/2

Show thread

There’s plenty of disagreement and controversy at the moment, so let me stoke things a bit more:

Light Mode is better than Dark Mode (for me)

Here’s why, with some science behind it, too. Yes, I have a justification as well just a preference…

Let’s start with what we know:
The pupil of the eye shrinks when there’s a lot of light and dilates when it’s darker

The question is: how much difference will it make between viewing a screen in dark mode and light mode?

Here’s a very rough, crude experiment (emphasis on “rough” and “crude”, and use of “experiment” is very loose here!)

Details in next toot

/1

Show more
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.