... no shit, here I am... taking a break from the redundantly recursive link sifting that is iOS development in the 21st Century. I can not count the stack pushes I've had since about 11 AM and it's only 6:37 PM still time for a beer and a pondering session...
A great story allways starts... no shit, there we were...
So at my Day Job <euphemism for what I get PAID to do... but I'm unemployeed> I'm writing a little easy
App for a colleague - it's a learning chance for me... and it might provide some value. I'm busily rewiring my brain (there is some question to its inherent plasticity) at my age - so ONE valuable technique is to get drunk enough not to care so damn much and bang out some crap one night - then in the morning come back and fix the hell out of it. There may be other valuable techniques...Well, last night I decided that the easy array data structure was just going to have to go... that was simple at first and went a long way - but I'd solve some of my current problems if I upgraded to a more ... let's say modern data structure. So I chose a Dictionary (Swift language)... and started ripping & tearing...
This morning I decided maybe I should look up the documentation on that Dictionary... that I may be thinking of recreating some of its built-in methods. Ya know, like random() and sort(). And it would be way cool if I could keep using the array subscript - since the retrieved order doesn't matter in most of the cases...
oh ... sorry gota take the D.O.G. for a walk - push that stack for me will-ya?
POP! - alright, where was this rant... getting to the good part... I hope...
So the dictionary class has a method call subscript that takes a Key & returns a Value(optional) - that's what that question-mark after Value means... it's an optional type thingy. Ok looking at the hightlighted method... subscript takes a Key and a ... what the MUCK and function named default that returns a Value. And then the whole method returns a Value. Why would I call the method with a function that returns the value - if I wanted the value... OK - I'm reading this WRONG... but what does it mean.
Let's go read up on Dictionaries at my go to resource HackingWithSwift.com by Paul Hudson. All-crap... the intertube is broken... maybe his site is down... maybe my tube is out... use my phone... yeah that's working, I'll go take a break and read up on Paul's site - he's better at explaining than all of Apple.
[ yes, I included the banner ad on purpose... Paul has been very helpful. ]
He's got a few pages about Dictionary... only while reading it the 20th time does it occur to me... that line right there - that ONE! "var adelScore = scores["Adele Adkins", default: 0]" It has the same form as the Apple Doc... that's what the documentation is trying to tell me... that I can pass in a default value that the method... what method... there is no SUBSCRIPT method - it's the Square Brack notation ... the one Fortran 77 invented... WTF Apple?!? If you mean [] couldn't you toss in some notation that (in parenthetical brackets of the [square] kind we mean...) subscript. Or maybe a footnote - or what do you call a footnote that's on the same page as the notation...
So I've spent the better part of the day trying to learn how to read the Apple Documentation. I figure that Apple is using some formal notation that I just don't understand... that IF I read up on the notation language they are using ... I will catch onto there ways. So I go GOOGLING the nature of Apple documentation and the symbolizm they use... I find out that they are using a MARKUP, or markdown, mark-across, marking-marky-mark (some level of Marxism) [ something Karl somebody dreamed up]; to write the documentaitiation in side the code... kinda like ol' James Gosling (Java) might have dreamed up.
Wasn't it Cobal that had the IN/OUT types... WTF! How does a normal little old programmer interpret that crap... I mean come-on APPLE! You can do better than this! Spend some money on a Human to write some docs for us.
What could this syntax mean?
What does that "get" out there mean? Do I use the lower case or upper case of Keys? Does it get a pair of parenthesis ()s? Or maybe some braces {}? Should I use angle brackets diction<>.Keys? Swift has lots of syntactical sugar. It's not naturally sweet! I need a decoder ring - where did they sell those...
Well it's now 8:02 PM and I've ranted enough - or drank enough beer to be in the "correct" frame of mind to tackle the code and replace my array with a Dictionary and till hell with those damn subscripts.
Hold my Beer!
It's morning now, and I'm revisiting my "productivity" or lack thereof... I realize I've achieved a touch of knowledge of Apple's documentation symbolism. This may be the learning process - enhanced by sleep (don't scoff - there is science underlying that statement). I still cannot parse the Dictionary keys line. But I can parse the subscript expression. I'm not sure they follow the same basic rules... for example in the subscript line - "default()" becomes a literal "default:" in the code. Whereas in randomElement description there are explicit "key:" and "value:" literals. I'm still looking for a rule book.
Comments