Length of an array and the case of an empty attic.

“I consider that a man’s brain originally is like a little empty attic, and you have to stock it with such furniture as you choose. A fool takes in all the lumber of every sort that he comes across, so that the knowledge which might be useful to him gets crowded out, or at best is jumbled up with a lot of other things, so that he has a difficulty in laying his hands upon it. Now the skillful workman is very careful indeed as to what he takes into his brain-attic. He will have nothing but the tools which may help him in doing his work, but of these he has a large assortment, and all in the most perfect order. It is a mistake to think that that little room has elastic walls and can distend to any extent. Depend upon it there comes a time when for every addition of knowledge you forget something that you knew before. It is of the highest importance, therefore, not to have useless facts elbowing out the useful ones.”

― Arthur Conan Doyle, A Study in Scarlet

What is the benefit of having this page embedded into your memory?

While there are legitimate reasons for languages to differ in approach, style and, consequently, their syntax – what is the reason why we can’t have length of array taken the same way in all or most of programming languages?

Groovy decided to be all original and went with ​.size() method. JavaScript obviously could not pass on opportunities for interesting decisions and .length is a property.  Kotlin – merge of the two previously mentioned, .size. Lua, geez, is there anything about this language that does not make you want to kill yourself – made #array the way to take length.

I’m not even going to comment this.

PHP! count()is the way.

Python. len(), because 2 letters make a difference.

Ruby – .length , Rust – .len(), Scala – .length

Guess what – "${#array[@]}".

Why do I have to store all of this rubbish in my head, taking space that might be used for something actually valuable and meaningful? Why do we limit the ability of collaboration between users of different languages? Why are we repeating errors made millennia ago, when life itself not-so-gently reminds us that usage of lingua franca, common system of measurement, common system of counting time, common system of geographical representation are vastly superior to localised solutions.

I mean, there is a word, length. That perfectly describes what is it we are after.

Length makes sense as an object property\field\whatever. It’s a characteristic of a thing.

Count is a verb which makes sense as an instruction for action to be performed on something – so a method taking something countable.

There’s nothing to discuss here. It’s a dead simple case having direct analogy in real world actions, and still there’s gazillion of different ways of doing same (incredibly simple and mundane) thing. Is it really surprising to find more complex concepts and actions represented by even bigger zoo of senseless naming conventions?

New languages are not really taking all this as an input to reduce the amount of rubbish in developer’s head. And I really wish someone would. Even more so, I’d wish existing languages would have future versions of the language change their own original solutions into something standard. Mathematics has done this quite some time ago. It’s about time computer science followed suit.

 

 

 

Advertisement

Hiking. Lessons learnt.

So I’ve returned from this hiking 3 day trip on the weekend and I’m sad to report that yours truly is an idiot.

First, I’ve been wrong assuming hiking pants are just marketing. Hiking in very dense fog/basically inside a rain cloud in +2 Celsius got my jeans soaked. I suppose quality hiking/snowboarding pants would be warmer, and more importantly, protect me from humidity better. We’ll see next time.

Second is – do check if the place you want to have a stop at is open. I was not the only person there to make a mistake – in fact there were like 40 people on the mountaintop expecting hot coffee and rest and seeing closed doors. That’s 99% the fault of the operator – there was no warning on their website whatsoever, but hey, fool me twice… Gotta call every place I plan on being open next time. 6 hours without any food was not fun.

Third one I knew but forgot about. Hiking backpacks, like my trusty Deuter 75+10 are still not waterproof. Pack your stuff into plastic bags if you don’t want them to get wet. Use a rain cover thingy that I don’t have. Don’t let minimalism bite you in the rear 😉

Fourth is Darwin award worthy. Given densest fog you’ve ever seen and visibility of 100 meters, a tele-zoom lens is useless. Duh.

Now for good things.

Nikon D500 is a beast. I love this camera. Backpacks don’t get any better than Deuter. My plan to work out in preparation to hiking trips did pay off, this one would not be possible had I not trained for it. https://mapa-turystyczna.pl is a great portal with a great Android app – works like a charm. Having 3 days off the grid(well kinda, but still) is amazing reset for the brain. I’m continuing my practice of journaling and boy did I write a lot on this weekend’s evenings. Physical act of writing with a good stationary is really “getting creative juices flowing” as my friend would say.

This one is pretty obvious.

If you are solving managerial problems by technical means, you will fail.

100% guarantee.

No amount of 10x developers writing best code the universe has ever seen will fix your undefined product priorities. Seems obvious, but it happens so damn often. Why is the company developing product X? Because we need team X to be doing something. Why are we ignoring technical issue Y? Because John Doe from team Z can’t agree with Jane Smith of team Q. All those are orthogonal.

Let’s talk stuff through, people.

Being there and getting there

There are these “meta” things you realise after being bewildered about something over and over again. So here’s one of mine.

We all make a mistake of thinking our goals come “bundled” with the ways of getting there. That it’s like a physical path to hike a mount to it’s top or some such. That doing something over and over again is bound to make you into whatever you want to be.

And therein lies the problem. Actually, there are tons of traps around this concept.

Many mistake what it takes to get somewhere and appearance of the goal they are trying to achieve. You don’t get to be an artist by making art you love. You get there by doing things that are not (yet) up to your standard.

Stolen from https://twitter.com/roostercastille/status/1042698000970203139

Basically you are going to feel bad about your art for long periods of time – because your taste for art is higher than the art you are able to produce. Then you will be satisfied for a while until your taste improves and you have to work to get back again.

This is an important concept in itself, but my point is – you won’t make it through the phase of dissatisfaction unless you enjoy the process. Unless you find a way to enjoy yourself while producing botched drawings or overexposed photos, making clumsy moves and being off pitch you’ll never be able to do it for years needed to attain mastery. At the same time if you are too comfortable with the subpar result you’ll just be very bad at something. The best way is to find and concentrate on the parts you did well, while acknowledging you have other stuff to work on. A good teacher is supposed to help students with that. Unfortunately that rarely happens. Students get praised for either absolute perfection, or simple participation. First makes sure there is little to no learning happening for those who did not came knowing the subject already, second guarantees nobody gets better – why try harder if you are number one, right?

Other very similar trap is a difference of what you want to be and what it takes to get “up there”. I thought I wanted to play music for quite some time. I tried several instruments, and hated every second of my life in the meantime. I hated practicing, I hated being focused at one piece at a time for really long, I hated doing things I am very bad at – fast coordinated movements synchronised with other people. Finally it occurred to me I wanted have exposure to music, not to play music. I wanted to be around musicians, not to be one myself. All of the things I envisioned about my success were satellites to the act I did not really enjoy doing (nor do I have natural skills for being good at it).

 

Related reading:

https://jamesclear.com/identity-based-habits

https://robinlawsart.com/blog/2015/10/28/real-life-artist-the-learning-curve

https://waitbutwhy.com/2018/04/picking-career.html

On appreciation of the web

Today’s web has lost one of it’s most endearing qualities – sense of community. For quite a while having access to the internet was an exception, rather then a rule. So when you’d get help from someone or find a cool resource with helpful information you’d feel lucky to be there. Lucky to be part of a community.

There are benefits to internet being a default now, clearly. But there’s one big downside to it, and it is dangerous. People largely just assume internet exists. Wikipedia is a thing. There is at least a dozen reviews(with photos) for every venue that serves food, everywhere on the planet. Youtube is basically obliged to have all the music you’ve ever listened to in full quality, right?

I’ve noticed that quality of the posts by the users of the website or a platform of some kind is the highest when it’s still small and as it gets more popular the quality plummets. Case in point – Facebook. Stackoverflow used to be good but once it became really popular it all went south. It’s been a year or so when I last found something of value in the answers related to my work on SO. http://forum.mflenses.com/ is an amazing community with so much things to learn about the subject running on a quite outdated platform. I bet that if they would migrate to a facebook or flickr group all that would just fall apart instantly.

I wonder if there are more elegant solutions to this hamster wheel issue then to just keep restarting communities when the previous gets out of hand.

Listening to https://remixsample.bandcamp.com/album/remixes-mostly-video-game-music

A metaphor for “return” in programming

I’ve recently been helping a brother-in-law with his studies and came up with a comparison that may be useful for someone else out there. While the idea of the function was pretty clear to my student, the concept of function returning a value was not.

I explained it this way. Imagine asking someone what time is it. “Alice, do you know what time is it?”. What do you expect to happen? Alice looking at her watch and saying nothing? Alice looking at her watch and saying – “yes I do know”? Or are you expecting and answer akin to “It’s half past three”? Here you have a function that does not have a return statement, a function that has hardcoded return statement of type boolean and a function that returns current time that was previously obtained by looking at the watch.

You could further explore this metaphor with types – by having Alice “return” different representations of the same time – 2PM, 14.00, “two in the afternoon”, “after midday”, “not late”, etc.

Perhaps one additional problem novices have with this idea is due to the fact their first functions are very small. If you have something like:


def a_function():
return "a value"

view raw

a_function.py

hosted with ❤ by GitHub

or worse yet, example with a simplistic class method:


def a_method():
return self.value

view raw

a_method.py

hosted with ❤ by GitHub

…then the student will likely be confused because those functions consist of return only. What is the purpose of it then? Or what is the purpose of a function? Valid questions that have sensible answers but not at the stage where it’s your student’s first coding experience. Throw in something simple that is not a return to avoid this confusion.

ror6ax has become a herbalist

So, after spending some time playing Dwarf Fortress and reading this awesome blog I’ve decided to try and grow my own plants from seeds. I am learning to grow bonsai, but all 4 plants I have so far are bought in local nursery.

It has a number of problems. Most frustrating one is nursery sells mostly things that are already larger than bonsai should be. They also do not sell a big variety of species I’d love to try growing. Growing stuff out of seeds is also fun, so I decided to give it a go.

My previous two attempts failed miserably.

I’ve tried doing what is known as cold stratification – put the seeds on a wet paper towel, get it into a plastic bag and put it into a fridge for 2-3 weeks.

img_20191002_145714.jpg

 

I was successful in growing a mould colony. None of the seeds germinated in 2 weeks. My first run had same results.

So I’m moving on to something else now.

IMG_20191002_145553.jpg

I’ve bought these peat pellets and some biodegradable pots made from coconuts. The picture has shown this one pellet filling the whole pot after getting soaked in water. As I expected, that was not exactly how it works, I needed 6 of these to fill my pot.

Now, I’m going to use some seeds from the supermarket apples, some seeds from 2 apples I picked on recent vacation and some crabapple seeds that survived the mould to see if pelt works better.

I’m not sure how the seeds will react given the +14 temperature outside and approaching autumn here in Wroclaw – but that is what experiments are for.

In the meantime, acorns that I’ve tried to germinate in other pots did not change a bit(I suppose they are either dead seeds or I’m dramatically underestimating time for them to sprout). I do have two maple saplings grown from seeds to boast though.

IMG_20191002_150909.jpg