Learning Elixir: Part 3

Hi All, Wow, we're already at part 3 and we're barely scratching the surface. I see a long road ahead with so much more learning to do. On the more positive side; I'm getting it and I'm finding it quite enjoyable so far... so let's crack on, shall we?

In the last few days I did two more experiments to do some basic sending and receiving between erlang processes (which I've come to find is a term which is interchangeable with BEAM processes, which is what I really mean).

My first task was to build a function (based on the video I linked to in part 1) that did some distributed work. So for this, I declared a function that took a list and a function and then the function would be applied to each item in the list. This was somewhat similar to a map() function in functional programming. Here's the Elixir part, each function would be run inside it's own Erlang process. Neato.

https://gist.github.com/samjarman/de7dd2337b425d1499cce16d0f1a5831

So, walking through the code, first we make a reference to the process by calling it me. Then on the list, we then map over the list, creating a function that spawns a process, which inside that sends back to the parent process a PID (self) and the result of applying the function to the element. Then on that list of PIDs we receive the result, and presto-we have a list of results. Pretty neat. With the task above, what wouldn't work is if the process was more complex (say, not multiplying a number by itself) and the process was to error out, nothing would rescue that... so that leads me to my next task.

My second task was to start playing with the concept of supervision, a reasonably crucial one in Elixir. I wanted to implement from scratch a really simple supervisor that would look at a randomly failing process and make sure it stayed alive.

https://gist.github.com/samjarman/7043ac55e9518969c8c1839d670d9622

So what I've done here is declared a worker function which fails just a little bit of the time, and if it does, it'll tell it's master about it before exiting. If the master hears about this, it'll respawn it and start listening all over again. Take a read through the code.

My next task is to start implementing some proper Elixir projects. There are also a few good ones to contribute to out there. If you have any suggestions for projects... I'm all ears!

Have you also been learning Elixir or Erlang too? Do you have any tips or comments? I’d love to hear them and share them in an upcoming post. Ping me on twitter.

Confusing Topics in iOS Development

Hi All, I thought it'd make an interesting post (hopefully?!) to talk about the stuff that still, after about seven years of tinkering with iOS to talk about the stuff that still confuses me sometimes, or things I always have to look up.

type-away-numero-dos

Bounds vs Frame

Like, wow... this always gets me. I generally work at a higher level of abstraction, but usually when I come to this I have to google it again and again. Frame is relative to superview, bounds to itself. Use frame or center for positioning and bounds for doing stuff inside the view, such as cropping.

Objective-C Block Syntax

Obviously. Side note: I was gonna link to Fucking Block Syntax but now I see it's Fucking Swift Block Syntax.

Compression Resistance vs Content Hugging

Let's be honest, AutoLayout has a hell of a learning curve, and by not touching UI much, I sometimes miss things with my spare time tinkering. I usually look up the below photo from @mokagio to remember. Also here's a good post on thatstatic1.squarespace

Setting  Text on a UILabel

Lol, like almost every time I do myLabel = @"foo"; rather than myLabel.text = @"foo"; Just one of those dumb things I can't seem to shake!

Logging a String

My brain is weird sometimes. I feel like my brain thinks "one day I'll be able to log an instance of NSString directly" so now and again I check. Nope.

NSLog(@"%@", myString); not NSLog(myString);

Of course, I know why it takes a string formatter argument rather than a string directly, but it still seems annoying to me. As I type this, I realise this could be "fixed" with a Macro?

Ex-Confusions

There are a few things I used to get confused about but then suddenly don't.

AutoLayout

When I first started learning AutoLayout, I was probably overthinking it or had the wrong mental model of how it worked.

The trick for me: Remember - two constraints, x pos and width, and y-pos and height. Satisfy those and you should be good to start with!

Dates and Times

Date and Time manipulation, formatting and timezones were always super confusing. My previous experience with these was with the C# DateTime library which worked a whole lot differently so it took me a while to get in the spirit of the Apple NSDate thinking.

The trick for me: Remember an NSDate is just an integer of seconds from 1970. The rest (timezone, format, components) is display.

Provisioning

I feel you were waiting for me to write this. People love to hate on provisioning but it's really not that hard? However, It can just break in so many ways and get frustrating. Just don't use the Fix Issues button (for now).

The trick for me: Taking the time to learn the parts. Signing Keys, Certificate, Provisioning Profile, WDC Certificate, App ID etc, Entitlements.


So that's my short list ranging from serious to less serious. I hope you feel less bad about being stuck on some things now. Remember: Chin up, you're probably not the only one feeling dumb about this stuff. Just ask!

How about you? What do you find confusing about iOS or development? Tweet me!

Thanks for reading!

Learning Elixir: Part 2

Hey All, Thanks for reading my last post - since then I've been doing a little more hacking and watching.

I believe the important thing with learning a new programming language is to focus on its strengths and weaknesses rather than just the syntax difference. Syntax is something you can learn quickly, but knowing the strengths and weaknesses of any language of tool can take an indeterminate amount of time.

Resources

I prefer to learn by really getting into the head of the people who came up with the language. One of those is Robert Virding, one of the original team members who worked on Erlang at Ericsson.

Here's a talk by him describing the Rationale of Erlang.

https://www.youtube.com/watch?v=rt8h_xeESLg

001

001

Another great resource is The Zen of Erlang. This (long) read covers some of the core principles and the mindset of Erlang (all of which are applicable to Elixir) Some other things I plan to watch and read are Learn You Some Erlang and this other talk by Virding. I was also suggested a book called The Little Elixir and OTP Guide Book. Do you have any more to add to this list? Let me know.

I had some more progress to talk about in this post, but I'll leave it for next time in the interest of keeping these posts short and to the point.

Have you also been learning Elixir or Erlang too? Do you have any tips or comments? I'd love to hear them and share them in an upcoming post. Ping me on twitter.