Wednesday, 22 January 2020

Win10 =? -2 cores

Just a few 10s of minutes ago I installed a Windows 10 enterprise on a VM.
Lo and behold, it's still eating roughly 2 (~ slightly deviating from the screenshot value, 60-70% on average) of  3 cores.
Er.... what on Earth for?
(The origin ISO was a quite recent download.)
I believe I do have hardware virtualization on my dev laptop, I tried waiting, I am too lazy to mention what I found on Google.
I never thought it would come to that, but praise the Lord for Ubuntu ;)

Friday, 3 January 2020

Stay nosy - notes about a couple of functional gadgets in Python

Mission briefing:

#1 lrucache() - does not always cache when you'd expect


(given an f(a): f(5) != f(a=5), or at least these mean two different calculations into the cache, and could even yield different values)

#2 partial() - you can still set the 'frozen' parameters


To begin with:

#1 lrucache()


It's a great thing to have something like this in the core set of a programming language.

However, beware: it will not consider an argument passed in as a keyword argument equivalent to the same argument passed in at its respective position.

A StackOverflow question is already dedicated to the topic - it was a bit of a surprise to me that this is so.

The below code demonstrates what I was at first surprised to expect to happen once I took a look at the lru_cache() implementation (for reasons irrelevant to the argument):

Next up:

#2 partial()


Now I must admit I am not a vigorous user of partial(), but I would have expected it to resist attempts to override the already 'frozen' (word from the Python documentation) parameters.  

"The partial() is used for partial function application which “freezes” some portion of a function’s arguments and/or keywords resulting in a new object with a simplified signature."

At least one risk here is that when part of a larger system, some code might change those values behind your back, breaking your assumptions.

I will try to remind myself to look at functions obtained via partial() as if they were simply provided a default value for some of their arguments.