Tag: Programming

  • My Journey to an iPhone App

    Like a lot of nerds, I’ve been coding since I was a kid – 14 years old, in my case.

    Unlike a lot of them, I’m much older. Teenage coders were few and far between in 1979.

    When the TRS-80 was announced/came out in 1978, I was 13 years old. And I begged my dad to get me one. I volunteered to do chores around the house, which, admittedly, I was terrible at. I hustled for money. I took my dad’s coin detector down to all the parks in Tucson and searched the sandboxes for change. The fundraising wasn’t going well.

    I just desperately wanted a computer. I didn’t have a goal in mind, but it was the coolest thing ever.

    True story: Computers were cool because of Star Trek, but I didn’t have my obsession for real-world computers until, some years earlier, when my dad had been given a box of fanfold green bar wide-carriage computer paper. He had no use for it, so it was given to me. That was also the coolest paper on the planet, and because it was for real computers, the coolness rubbed off onto the computers.

    I hadn’t chosen my direction in life by that point and was vacillating between a career as a paleontologist or a forest ranger, and I certainly didn’t realize it at the time, but that box of paper set me on my path of destiny.

    In 1979, my dad had planned a summer-long camping excursion from Arizona to Alaska by way of New Mexico, Colorado, Wyoming, Montana, Idaho, Washington, British Columbia, the Yukon Territory, and finally, Alaska. Alaska had been on his and my mother’s radar as their dream camping destination since before I was born. They never made it before she died, and my dad clung to the idea, and now he was going to make it a reality.*

    It would just be my dad and myself. We had a hard-top, soft-side pull-behind tent camper, and I wasn’t necessarily keen on being on the road for almost three months with no TV. You can play only so many cribbage games against your dad (and be soundly beaten) before the allure wears off. This was the longest camping trip he’d ever planned, and I think he detected my reticence.

    So he bribed me.

    For the trip, he agreed to spend roughly 50% of the time staying at KOAs. He could justify this because they always had showers, and we could clean up every few days. They also had electrical hookups. He bought me a small portable, black and white, A/C & battery-powered TV, with a 5″ screen, and a TRS-80 Model I, Level I computer.

    I spent that summer in a tent, learning to program a computer. And I didn’t just learn TRS-80 BASIC, either. I also had to learn Apple II BASIC because, in those days, there were magazines that would print source code for you to type in, but often the magazines would support multiple hardware, and sometimes the program you wanted was an Apple program. I learned Apple BASIC without access to an Apple computer so that I could port the program to the TRS-80. (It was not always possible.)

    I clickety-clacked my way through that trip on that TRS-80. I was compulsively obsessive about it. I loved it.

    It wasn’t long after the trip I wrote my first program and got paid for it. It was a ridiculously simple program (by today’s standards) to store daily stock prices by ticker symbol and graph them historically versus the DJIA. Was it actually useful? Probably not, but it was what the customer wanted.

    I have been coding for what seems like an inconceivably long time.

    The other day I tried thinking about all the programming languages I’ve learned over the years, and I can’t enumerate them all.

    There was TRS-80 BASIC and Apple II Basic. (Integer BASIC, maybe?) I went to community college, which was all about COBOL-68 and FORTRAN-77 on punch cards! At university, it was UCSD Pascal, or machine code, on DECwriter terminals. Somewhere in there, I bought an IBM PC – the TRS-80 had long since died – and started learning Turbo Pascal and became an absolute whiz at batch programming.

    My first salary computer job with a corporation had me learn an incredibly obscure language called Micro-Adapt, which was, as far as I can tell, a PC implementation of an obscure database language for some larger systems. I have never successfully found a trace of either language on the Internet, but they existed. I picked up Oracle SQL shortly after that, and then we got an AS/400, which I had to learn from scratch, without any training. I started with BASIC/400 and SQL/400, and I was able to put together the programs needed to replace the Micro-Adapt, but the performance was really lackluster. So I taught myself RPG III and RPG IV/400, and that improved their performance so greatly that I re-wrote all the programs in RPG.

    Knowing RPG was good for me, and my salary jumped greatly when I moved to my next RPG job. There, I also had to pick up dBase III/IV, Clipper, VBA, HTML, and JavaScript.

    In the last few years before my retirement, I moved to the realm of OOP and Java programming.

    And I thought, 20+ languages is probably good enough for a lifetime. I’m probably missing a few, and I’m sure most of it’s forgotten.

    You might have noticed that C or C++ is not on that list. I’ve never needed to learn C for anything. Its ubiquity made me feel like I ought to learn it; I tried a couple of times but can not take in a programming language without a clear-cut objective. I’m familiar with it and can decipher some of it, but it’s never taken root.

    A while back, I decided that I should learn to program the iPhone. I could perhaps get rich in my spare time! Once again, without a specific goal, I tried learning Objective-C and Cocoa Touch, which didn’t go well. Perhaps my brain was ossifying, but I had real problems getting my head around Cocoa Touch’s implementation of MVC, and eventually, I just gave up.

    About a year ago, two things happened. My trusty HP-28S calculator died. (Oh, yeah, there’s another one, I used to program that in RPL.) I replaced it with an HP Prime Calculator, which uses PPL to program. The other thing that happened was that I started playing the Guardian’s Killer Sudoku puzzles. (I subscribed to have a steady source of Cryptic Crosswords to learn to solve, which I’m crap at, but I got addicted to the Killer Sudokus. I suspect there’s probably a deep insight into my mind in that if we just dig a little.)

    There are a number of charts and math tricks you can use to help solve Killer Sudokus and with the new calculator very fresh in my mind I realized this was a specific goal that I could use to learn PPL. So I did, and the program is really helpful… or at least, it used to be, because eventually, it all gets committed to brain muscle memory, and I found myself using it less and less.

    There is also an HP Prime emulator that you can get for your iPhone, and I loaded that and my Killer Sudoku Killer program on it, and when I did find myself needing the program, I was using it on my iPhone rather than the actual calculator.

    And then I slapped myself on the forehead, shouting ‘D’oh!” when I realized that this was the specific goal I should have used to learn to program the iPhone.

    Objective-C and Cocoa Touch have given way, at least partially, to Swift and SwiftUI, and so I started from scratch once more to learn to code the iPhone exclusively with Swift and SwiftUI.

    That adventure is another post, but just a few hours ago, I submitted version 1.0 of Killer Sudoku Aide to Apple for review and hopeful inclusion in the App Store.

    And now I wait. Will it get accepted or rejected, and if so, why? What perceived sin might I have committed against the capricious Apple App Store Review Gods?

    Time will tell.


    *We never made it to Alaska. Outside Santa Fe, NM, my dad was stung by something on the finger, and it started to swell up. After a few days, hunkered down in one spot in the woods, it was still getting worse, so we moved on to Denver, CO, where he saw a doctor seeking treatment. They treated it, and it seemed to be improving, and we continued on, but it never healed completely.

    Having lost time, my dad tried to accelerate the trip, and within a couple of weeks, we were in Seattle, WA. The finger was swelling and being gross again, and he had to seek more medical treatment. This time they cut it open, drained it, removed something that was in there, and sewed it back up.

    My dad had had enough. He was in a lot of pain and not enjoying the trip. We turned south through Oregon and California and returned home. My dad never made it to Alaska. For that matter, neither have I. Yet.

  • Adventures in Objective-C – Part 1

    I’ve been trying to get my head around Objective-C and Mac/iPhone programming for the last month or so. At this point, I think I’ve got most of the major concepts down.

    As an Object Oriented (OO) language, it bears a certain familial resemblance to Java, which I typically program in these days.

    While I’m not going to say that Java is a “better” language, I do feel that parts of Objective-C are a capricious conglomeration of logic-unfriendly syntax.

    It’s the implementation of these things that’s irritating. Obviously there’s a certain amount of familiarity and personal preference, but over this series of articles, I’ll highlight a few. I’ll start with a simple syntax example.

    Generally in OO programming, you break things into programatic “objects”, which define the properties of an object and the actions that such an object could do.

    In Java speak, these are properties and methods, in Objective-C they are properties and selectors. In Java you “call” a method, in Objective-C you “message” a selector. Same thing, different terminology. Clear as mud? Good, then let’s continue.

    Typically, properties on an object are protected behind accessor method, such as “getXXXX” and “setXXXX” where XXXX is the property name. Sometimes these are called “getters and setters” – that’s in Java, of course, Objective-C calls them “accessors” and “mutators”. Objective-C also uses a slightly different convention. Mutators are still “setXXXX” but accessors are just “XXXX”, which can result in a little ambiguity as to whether you’re looking at the actual property variable or the accessor selector.

    Java uses “dot-syntax” to refer to an object’s methods, so far example, if you have an object called “newton” and it has a method called “dropApple()”, you would access it like this:

    newton.dropApple();

    Objective-C uses square bracket syntax, so the same thing would be:

    [newton dropApple];

    …and if each one took a single parameter, they would look like this:

    newton.dropApple(velocity);

    vs

    [newton dropApple:velocity];

    It gets a little muddier when we move to two parameters.

    In the example above, I’ve passed a variable called “velocity” which we’ll say is of object type “Speed”. Let’s add a second object type of “Height”, with an instance variable called “headHigh”

    We would DECLARE the java method like this:

    void dropApple(Speed incomingSpeed, Height incomingHeight) {

    …. do stuff

    }

    and call it like this

    newton.dropApple(velocity, headHigh);

    Objective-C would be declared like this:

    (void)dropApple:(Speed *)incomingSpeed dropHeight:(Height *)incomingHeight {

    …. do stuff

    }

    and called like this:

    [newton dropApple:velocity incomingHeight:headHigh];

    Here’s my first irritant, Objective-C selectors use named parameters – which I like better than Java, but only on the second and subsequent parameters. The first is identified by the name of the selector. It’s just a mixed-bag inconsistency. I hate inconsistencies in my programming languages.

    This same system also helps cause Objective-C messages to tend to be very long.

    Java and Objective-C also share another trait, that being if a message/call returns an object, you can then, in turn message/call that object immediately without passing it through an unnecessary intermediary object variable.

    Let’s say we’re somewhere inside an object that is running active code – like a program. I can always reference back to myself with the special keyword “self”, so if my program has a property of type Person, and a Person object has a property of type “phoneNumber” and a PhoneNumber has a method that returns a formatted representation of the number, we can get to that formatted string in java like this:

    self.getPerson().getPhone().format();

    Self being an object with a getPerson() accessor that returns a Person, which in turn has a getPhone() accessor which returns a Phone, which in turn has a format() method to return a pretty string. It’s not uncommon to see these things strung together 4 and 5 levels deep inside Java code, and it’s a bit difficult to read, but convenient, and sometimes a lot better than assigning each step to a new variable, like this:

    Person aPerson = self.getPerson();

    Phone aPhone = aPerson.getPhone();

    String aString = aPhone.format();

    How does Objective-C handle this? Like this:

    [[[self person] phone] format];

    Simpler, right? Yes and No. It’s irritating. Why? Because you have to know, in advance, how many layers deep you are going so that you can put the right number of square brackets on the left. If not, you have to come back later and add them, which really “breaks the stride” of typing. It may be less letters to type, but it takes longer to type.

    Ah, but along comes Objective-C 2.0 with a “solution” to this: Dot-Syntax!

    Oh, but it isn’t the same as Java’s dot-syntax. Objective-C’s dot-syntax only applies to properties, not selectors. (Actually, properties are selectors, you’re not seeing the actual variable, but these are special) That means you can do this:

    self.person;

    or

    self.person.phone;

    but not

    self.person.phone.format;

    instead it would be:

    [self.person.phone format];

    Why is this a problem? You don’t always know if something is a “property” or “selector”, and since the IDE (XCode in this case) helps fill this stuff in from it’s calculated list of available options, it promotes a certain natural “coding laziness” by letting the IDE do the work of remembering names for you.

    So you start typing “self.pe…” and about that time it suggests “self.person”, so you hit the arrow and continue typing “.ph…” and it breaks in again and suggests .”phone” so you hit the arrow to accept and then you start “.format” and nothing happens, then you realize, “oh, it’s not a property”, so you go back and delete the period. That’s bad typing technique. And, then, of course, you have to go back to the beginning of the clause to add a “[” and the end of the line to add “]”

    I know, I know. “Gripe, gripe, gripe, gripe”

    Next time (probably) “Why there isn’t a consistent method for delegates, actions and ad hoc delegates”