Joep Schuurkes (Posts about python)https://smallsheds.garden/categories/python.atom2023-12-29T09:12:45ZJoep SchuurkesNikolaA lesson from every language I've usedhttps://smallsheds.garden/blog/2023/a-lesson-from-every-programming-language-ive-used/2023-12-29T00:00:00+01:002023-12-29T00:00:00+01:00Joep Schuurkes<div><p>Throughout the years I've used quite a few different languages - if you allow me to be somewhat generous with the word "use". One language I actually feel proficient in. Some languages I've only done coding exercises in. And one language I've only used for a total of maybe 10 minutes, but that did really help out a whole team.</p>
<p>I do believe we should be that generous, both towards ourselves and to others. For an industry that likes to talk about imposter syndrome, we seem to enjoy saying <em>"You're not a real ... unless..."</em> a bit too much.</p>
<p>Listing these languages for myself made me wonder what I had learned from them. Did I just learn how to write some code in each of them? Or did I also pick up some more general lessons? Turns out I did.</p>
<p><a href="https://smallsheds.garden/blog/2023/a-lesson-from-every-programming-language-ive-used/">Read more…</a> (5 min remaining to read)</p></div>(clj 9) How to figure out what a function doeshttps://smallsheds.garden/blog/clojure/2022/clj-9-how-to-figure-out-what-a-function-does/2022-06-12T15:01:36+02:002022-06-12T15:01:36+02:00Joep Schuurkes<div><p>Chapter 4 of "<a href="https://www.braveclojure.com/clojure-for-the-brave-and-true/">Clojure for the Brave and True</a>" concludes with a <em>Vampire Data Analysis Program</em>, serving as a summary of the chapter. The book shows some code, explains it, moves on to the next bit of code, etc. I'm not sure why, but I decided I wanted to figure out the code on my own and then read the explanation to see if I got it right. Afterwards I realized it might make a good blog post: both explaining what the program does and what techniques (for lack of a better word) I used to figure it out.</p>
<p>With most of the work in the program being done by a function called <code>mapify</code>, this blog post will focus on that single function. As it turns out, it took me more than 2000 words (footnotes not included) to describe what this function consisting of only 9 lines does. So feel free to read all of it, skim through it, or skip straight ahead to the <a href="https://smallsheds.garden/blog/clojure/2022/clj-9-how-to-figure-out-what-a-function-does/#techniques">techniques</a> and some <a href="https://smallsheds.garden/blog/clojure/2022/clj-9-how-to-figure-out-what-a-function-does/#reflections">reflections</a>.</p>
<p><a href="https://smallsheds.garden/blog/clojure/2022/clj-9-how-to-figure-out-what-a-function-does/">Read more…</a> (16 min remaining to read)</p></div>(clj 8) Some notes on lazy sequences and function parametershttps://smallsheds.garden/blog/clojure/2022/clj-8-some-notes-on-lazy-sequences-and-function-parameters/2022-04-18T14:16:36+02:002022-04-18T14:16:36+02:00Joep Schuurkes<div><p>Almost done with the chapter 4 <em>"Core Functions in Depth"</em> of "<a href="https://www.braveclojure.com/clojure-for-the-brave-and-true/">Clojure for the Brave and True</a>"! Before wrapping up the chapter with a longer example, a summary, and some exercises, the book goes into lazy sequences, the collection abstraction, and function functions. In this post I will share some notes on infinite lazy sequences and function parameters, making comparisons between Clojure and Python.</p>
<h2>Infinite lazy sequences</h2>
<p>A lazy sequence is a sequence whose members aren't computed until you try to access them. One advantage is that it's more efficient: the whole sequence doesn't have to be calculated and kept in memory from the start. Another advantage is that it allows you to create infinite sequences. Do that with a normal sequence and your program would never want to stop calculating.</p>
<p><a href="https://smallsheds.garden/blog/clojure/2022/clj-8-some-notes-on-lazy-sequences-and-function-parameters/">Read more…</a> (4 min remaining to read)</p></div>(clj 7) Programming to abstractions with sequence functionshttps://smallsheds.garden/blog/clojure/2021/clj7-programming-to-abstractions-with-sequence-functions/2021-12-05T13:40:36+01:002021-12-05T13:40:36+01:00Joep Schuurkes<div><p>Looking at my progress so far, I realized it's time re-evaluate this whole learning Clojure-thing. After looking through the table of contents of "<a href="https://www.braveclojure.com/">Clojure for the Brave and True</a>" and giving it some thought, I decided to make two changes to how I'll proceed:</p>
<ul>
<li>I will start writing shorter posts and write them more often.</li>
<li>My goal is to finish <em>"Part II: Language Fundamentals"</em>. I don't have to do <em>"Part III: Advanced Topics"</em>.</li>
</ul>
<p>Completing Part II will still take quite some work. I've worked through the two first sections of chapter 4 (5 sections left in that chapter) and Part II goes up to chapter 8. So no time to waste: let's take a look at sequence functions and programming to abstractions.</p>
<p><a href="https://smallsheds.garden/blog/clojure/2021/clj7-programming-to-abstractions-with-sequence-functions/">Read more…</a> (7 min remaining to read)</p></div>(clj 5) Loop and recur, into and conjhttps://smallsheds.garden/blog/clojure/2020/clj5-loop-and-recur-into-and-conj/2020-12-26T10:09:08+01:002020-12-26T10:09:08+01:00Joep Schuurkes<div><p>Yet again it's been a while since I did some Clojure or blogged about it. This time I'm writing this blog post
three months after working on the code on September 5, 6 and 12. I'm not going to dwell on that too long, because
other things in my life were more important. I did feel a little sad when this year's <a href="https://adventofcode.com/">Advent of Code</a>
launched and I realized my Clojure is nowhere near a state where I could attempt the puzzles. So I ended up doing
the first 10 days in Python, which is twice as far as I got last year.</p>
<p>I also feel like my current approach to learning lends itself well enough to going slow. Taking my time to play around
and make notes with while working through a section of <a href="https://www.braveclojure.com/">Clojure for the Brave and True</a>
and then revisiting my code and notes later to write a blog post, does seem to result in stuff actually sticking in my memory.
(Disclaimer: am writing this before writing the rest of this blog post.) Slow is smooth and smooth is fast, as they say.</p>
<p>The section I tackled in September is "Pulling It All Together" from Chapter 3, which describes the construction of a
piece of code of about 50 lines in which - I'm sorry to say - a hobbit gets hit in different body parts.</p>
<p><a href="https://smallsheds.garden/blog/clojure/2020/clj5-loop-and-recur-into-and-conj/">Read more…</a> (6 min remaining to read)</p></div>(clj 3) Clojure's 'and' and 'or' are weird (but not really)https://smallsheds.garden/blog/clojure/2020/clj3-and-or-being-weird/2020-05-16T21:25:15+02:002020-05-16T21:25:15+02:00Joep Schuurkes<div><p>Early in <a href="https://www.braveclojure.com/do-things/#Control_Flow">chapter 3</a> of the <a href="https://www.braveclojure.com/">Brave and True</a>-book the Boolean operators <code>and</code> and <code>or</code> are introduced:</p>
<blockquote>
<p>Clojure uses the Boolean operators <code>or</code> and <code>and</code>. <code>or</code> returns either the first truthy value or the last value. <code>and</code> returns the first falsey value or, if no values are falsey, the last truthy value.</p>
</blockquote>
<p>This explanation is followed by some examples:</p>
<div class="code"><pre class="code literal-block"><span class="p">(</span><span class="nf">or</span><span class="w"> </span><span class="nv">false</span><span class="w"> </span><span class="nv">nil</span><span class="w"> </span><span class="ss">:large_I_mean_venti</span><span class="w"> </span><span class="ss">:why_cant_I_just_say_large</span><span class="p">)</span>
<span class="c1">; => :large_I_mean_venti</span>
<span class="p">(</span><span class="nf">or</span><span class="w"> </span><span class="p">(</span><span class="nf">=</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="p">(</span><span class="nf">=</span><span class="w"> </span><span class="s">"yes"</span><span class="w"> </span><span class="s">"no"</span><span class="p">))</span>
<span class="c1">; => false</span>
<span class="p">(</span><span class="nf">or</span><span class="w"> </span><span class="nv">nil</span><span class="p">)</span>
<span class="c1">; => nil</span>
</pre></div>
<div class="code"><pre class="code literal-block"><span class="p">(</span><span class="nf">and</span><span class="w"> </span><span class="ss">:free_wifi</span><span class="w"> </span><span class="ss">:hot_coffee</span><span class="p">)</span>
<span class="c1">; => :hot_coffee</span>
<span class="p">(</span><span class="nf">and</span><span class="w"> </span><span class="ss">:feelin_super_cool</span><span class="w"> </span><span class="nv">nil</span><span class="w"> </span><span class="nv">false</span><span class="p">)</span>
<span class="c1">; => nil</span>
</pre></div>
<p>What I found remarkable about this is that <code>and</code> and <code>or</code> do not return a boolean in all cases. Before I go into that, let's back up a second and cover their basics in a little more depth first.</p>
<p><a href="https://smallsheds.garden/blog/clojure/2020/clj3-and-or-being-weird/">Read more…</a> (7 min remaining to read)</p></div>Getting [name] from "Name: [name]" in Python - an engineering problemhttps://smallsheds.garden/blog/2019/getting-name-from-name-name-in-python-an-engineering-problem/2019-08-26T21:27:38+02:002019-08-26T21:27:38+02:00Joep Schuurkes<div><p>Today I was presented with an interesting engineering problem. (Important later: context was the code of an auto-test.) Given a string of the format "Name: [name]", what's the best way to get the [name] in Python?</p>
<p>There are several options:</p>
<ul>
<li><code>lstrip()</code></li>
<li><code>split()</code></li>
<li><code>replace()</code></li>
<li>string slicing</li>
<li>regex</li>
</ul>
<p>So let's look at each of them and then I'll explain which one I prefer and why. All examples are in Python 3.6, using the <a href="https://docs.python.org/3.6/tutorial/interpreter.html">Python Interpreter</a>.</p>
<p><a href="https://smallsheds.garden/blog/2019/getting-name-from-name-name-in-python-an-engineering-problem/">Read more…</a> (5 min remaining to read)</p></div>How this tester writes codehttps://smallsheds.garden/blog/2019/how-this-tester-writes-code/2019-06-08T18:21:38+02:002019-06-08T18:21:38+02:00Joep Schuurkes<div><p>A long time ago (March 2015) I wrote a post titled "<a href="https://smallsheds.garden/blog/2015/test-automation-five-questions-leading-to-five-heuristics/">Test automation - five questions leading to five heuristics</a>". Later that year <a href="https://twitter.com/richrtesting">Rich Rogers</a> asked for a follow-up. To which I replied I should do a follow-up post (ahum) "soon".
Then last Wednesday <a href="https://twitter.com/noahsussman">Noah Sussman</a> said on <a href="https://twitter.com/noahsussman/status/1136288062651142149">twitter</a>: <em>'I don't know that I've *ever* seen "this is how testers write code"'</em>. To which I replied "challenge accepted", so now here we are, me writing a blog post about how I as a tester write code.</p>
<p>The format of this post turned out to be advice based on my experiences, so the usual disclaimers apply. And feel free to leave a comment if you have any feedback!</p>
<h3>The basics</h3>
<h4>use an IDE</h4>
<p>An IDE is not just an advanced text editor. It understands your code - to a degree, since it's not interpreting, compiling or executing the code. So not only allows an IDE you to manipulate your code as text, it also allows you to manipulate your code as code.</p>
<p><a href="https://smallsheds.garden/blog/2019/how-this-tester-writes-code/">Read more…</a> (14 min remaining to read)</p></div>Solving Black Box Puzzle 31 with data analysishttps://smallsheds.garden/blog/2019/solving-black-box-puzzle-31-with-data-analysis/2019-04-28T13:16:34+02:002019-04-28T13:16:34+02:00Joep Schuurkes<div><p><a href="https://twitter.com/workroomprds">James Lyndsay</a> has created a number of amazing <a href="http://blackboxpuzzles.workroomprds.com/">Black Box Puzzles</a>: tiny applications that challenge you to figure out what they do. (You can support him in creating more of these at <a href="https://www.patreon.com/workroomprds">his Patreon page</a>.) Two of these Puzzles, <a href="http://blackboxpuzzles.workroomprds.com/puzzle29/">29</a> and <a href="http://blackboxpuzzles.workroomprds.com/puzzle31/">31</a>, not only have a GUI to explore, but also an API.</p>
<p>And that gave me an idea. If you explore these Puzzles through their GUI, you start from the inputs. You try out different inputs in the hope of discovering a pattern in the outputs. And then that pattern feeds back into your exploration.<br>
With an API, however - and because of the nature of Puzzle 31 - it becomes easy to get the outputs for all possible combinations of inputs. Which means you can start your exploration from the outputs instead of the inputs.</p>
<p>Before I tell you how and what I did, three important remarks.<br>
First of all, I will be spoiling the solution to the Puzzle in this blog post. So this is the right moment to go and solve <a href="http://blackboxpuzzles.workroomprds.com/puzzle31/">Puzzle 31</a> for yourself first. Or at least go play a bit with it, so you have an idea what the inputs and outputs are.<br>
Secondly, I had already solved the Puzzle through the GUI a few months ago. So it was more of a "Can I find the solution this way as well?" than a "Can I find the solution?" thing.<br>
Finally, the code and the spreadsheet I created (linked throughout, also available on GitHub <a href="https://github.com/j19sch/blackbox-puzzle-31">here</a>), are not very clean. I thought about tidying them up, but my two reasons for not doing so are (1) laziness; (2) the way they are now gives a more honest picture of what I did.</p>
<p><a href="https://smallsheds.garden/blog/2019/solving-black-box-puzzle-31-with-data-analysis/">Read more…</a> (18 min remaining to read)</p></div>