Guardians of the Galaxy 3

Hell yeah. I grew up with some of my favorite comics being ROM Spaceknight, Nova, Rocket Raccoon, Adam Warlock (in Marvel Presents, I think?), and so on… the Marvel space series were so much better than their ground superheroes. While the films are a little trashy, they’re fun trash, and the music was just awesome.

But then some Nazis doxxed Gunn and Disney was like “I’m shocked, shocked I say, to discover that the writer of Tromeo & Juliet makes dirty jokes!”, but happily have seen sense since everyone involved wanted him back.

So here’s the music again:

Return of the Objective-C Jedi

[[[ These ]]] are your father’s square brackets, the weapons of a Jedi Knight.
Not as clumsy or random as C++.
Elegant weapons for a more civilized age.

What’s Different in Mulle-ObjC

This is like Objective-C circa 2010(?), good but not fully baked. Far better than circa 1986-2009, when it was a very thin translation layer over C.

  • No ARC (Automatic Reference Counting). This is just invisible sugar to hide retain/release/autorelease, and while ARC’s convenient, it’s trivial if you actually know how reference counting works. Don’t really miss it.
  • No dot property syntax. [[myObj name] length] instead of myObj.name.length, and [myObj setName:newName] instead of myObj.name = newName. I can live with it, but I really did like dot syntax, even if it does “overload” the . operator and hide the distinction between methods and variables.
    • When dot syntax came out, Objective-C nerds came close to fistfights over this. You would not believe the venom some people had for it. Most of those nerds died or quit or got old & tired before fucking Swift came around, I guess.
  • No array syntax. [myList objectAtIndex:i] instead of myList[i]. This is a pain in the ass, I’ll have to write some shorthand macros (or rather, go dig them out of my very oldest code).
  • No blocks. This one hurts, but it’s a reasonable pick-your-battles decision. Classic: Write a method, dispatch to it, and call back success somehow. Blocks: create a weakSelf reference, enclose it, search-replace self in your block, pick one of a half-dozen complex GCD methods, get a memory leak because you retained something across the block boundary. This is annoying but logically simpler:
    [self performSelectorInBackground:@selector(computeData) withObject:inputData];
    
    - (void)computeData:(id)inputData {
        // create outputData
        [self setOutputData:outputData];
        [[NSNotificationCenter defaultCenter] postNotification:NOTI_DataComputed];
    }
    
  • Has object literals: @42 and @(var) create an NSNumber, @[] creates an NSArray, @{} creates an NSDictionary; dicts use key:value order, not the reverse order used in -[NSDictionary dictionaryWithObjectsAndKeys:], and array and dicts don’t need a trailing nil, which was a constant source of mystifying bugs back in the day. Big win!
    • Hmn, crashes if you do something janky like [@[] mutableCopy]: mulle_objc_universe 0x1006adef0 fatal: unknown method 5e1b0403 "-getObjects:range:" in class 7aa0d636 "_MulleObjCEmptyArray"
  • Has for (id x in container) loops, using NSFastEnumeration. The 1.0 process of looping enumerations was awful, so this is very nice.
  • Huh, does have @autoreleasepool, so maybe I should use that instead of NSAutoreleasePool like a caveman? It compiles and seems to work.
  • Properties have properties assign/retain nonatomic/atomic nonnullable readonly, default is assign nonatomic, no “nullable” or “readwrite” flags needed. As it should be.
  • Weird isa define instead of pointer: blog post

TODO

  • I haven’t set up an NSRunLoop or the equivalent of NSApplication (which is in AppKit, not Foundation), need to do that and then I’ll have a working app template.

Writing Objective-C with Mulle-Objc

mkdir CLICalc
cd CLICalc
mulle-sde init -m foundation/objc-developer executable

This takes more or less forever.

… Still going. OK, finally done. I hate to think it’s gonna do that every new project? Or whenever it updates?

Anyway, bbedit . (fuck Xcode), and add at the bottom of import.h and import-private.h:

#import <Foundation/Foundation.h>

Make src/main.m useful:

// main.m
#import "import-private.h"
#import "CLICalc.h"

int main(int argc, char *argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    CLICalc *calc = [[CLICalc alloc] init];
    [calc push:42.0];
    [calc push:69.0];
    double a = [calc pop];
    double b = [calc pop];
    NSLog(@"a=%f, b=%f", a, b);

    [pool release];
    return 0;
}

Create an Objective-C class, src/CLICalc.h:

// CLICalc.h
#import "import-private.h"

@interface CLICalc : NSObject

@property (retain) NSMutableArray *stack;

- (void)push:(double)n;
- (double)pop;

@end

and src/CLICalc.m:

// CLICalc.m
#import "CLICalc.h"

@implementation CLICalc

@synthesize stack = _stack;

- (id)init {
    self = [super init];
    _stack = [[NSMutableArray alloc] init];
    return self;
}

- (void)dealloc {
    NSLog(@"CLICalc dealloc");
    [_stack release];
    [super dealloc];
}

- (void)push:(double)n {
    [_stack addObject:@(n)];
}

- (double)pop {
    if ( ! [_stack count]) {
        // ERROR: stack underflow
        return 0.0;
    }
    double n = [[_stack lastObject] doubleValue];
    [_stack removeLastObject];
    return n;
}

@end

Doing that without a template was a little hard on the old memory, and I had to use DDG to look up some method names without autocompletion. But I’m pretty sure that’s fine.

In mulle-ide, type update to add the new class to cmake: If you look in cmake/_Sources.cmake you should now see CLICalc.m listed.

Now craft to compile. You’ll get a spew of crap, but hopefully no errors.

I am getting this, which I can’t resolve:

/Users/mdh/Code/CodeMac/CLICalc/src/main.m:21:55: warning: 'NSAutoreleasePool'
      may not respond to 'init'
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~ ^
1 warning generated.

But NSAutoreleasePool certainly has init, and it seems to not die?

% ./build/Debug/CLICalc
a=69.000000, b=42.000000

Hooray!

Yeah, this isn’t amazing. Except: It’s supposedly portable now. I can maybe rebuild this on Linux, or Windows? I dunno.

This is almost classic Objective-C, slightly enhanced from 1.0: We didn’t have property/synthesize, or nice object wrappers like @() when I were a lad. I typed so many [NSNumber numberWithInteger:n]. So get used to the retain/release/autorelease dance. There’s no dot-syntax for property access, type them [] like old-school. But hey, it’s a proper compiled language with a nice object system and no GC pausing.

I tried importing Cocoa and got a ludicrous spew of errors, so Mac GUI is gonna be a challenge. But I could import SDL and use that for portable UI, since Objective-C is just C.

Sweet. I’ll finish up the calculator’s parser in a bit, but then see about doing something useful in it.

Interactive Python IDLE

When using Python from a shell, the REPL is fairly awful and doesn’t let you copy-paste or save, except through the shell itself. I especially find that copy-pasting functions in is error-prone. There’s a nice interactive environment for Python called IDLE (after Eric ): It’s probably an application in your /Applications/Python 3.7 folder, or whatever other OS’s do, or can be run with IDLE3 from the shell. Other than using ^N/^P for next/previous history line, it works pretty much exactly as you’d expect a GUI REPL to work, and lets you save your session as a text file, easy to extract some functions from later or use as a doctest.

Trouble is, IDLE doesn’t automatically pick up the ~/.pystartup script; I had to remember to call it with IDLE3 -s, and there’s no easy way to do that from the desktop, where I’m often lazily clicking. This has been frustrating me very slightly for years.

So: open Automator, new Document, add Utilities/Run Shell Script, and paste in:

IDLE3 -s

Save as an Application, name it IdleStart. The icon’s ugly and generic, so I made a half-assed icon, copy it from an image editor or Preview, and paste into the icon in Get Info on the application.

python-foot

Now I have a nice stupid foot to click on, and get a proper REPL. The running program has a hideous 16×16 or 32×32 icon scaled up, which I don’t think I can easily solve; I looked at the idlelib source and while I could patch it, it’s not easily configured. Maybe later. There’s also no way to specify the window location, which I’d like to have mid-left of my screen, but again, maybe later.

While I’m at it, the themes are garish, and the customizer is unpleasant. So I just edited this in ~/.idlerc/config-highlight.cfg, then picked Mark’s Dark theme:

[Mark's Dark]
normal-foreground = #eeeeee
normal-background = #111111
keyword-foreground = #ff8000
keyword-background = #111111
builtin-foreground = #0099ff
builtin-background = #111111
comment-foreground = #dd0000
comment-background = #111111
string-foreground = #80ffdd
string-background = #111111
definition-foreground = #80ff80
definition-background = #111111
hilite-foreground = #ffffff
hilite-background = #808080
break-foreground = #ffffff
break-background = #808000
hit-foreground = #002040
hit-background = #ffffff
error-foreground = #ffffff
error-background = #cc6666
cursor-foreground = #ffffff
stdout-foreground = #ccddff
stdout-background = #111111
stderr-foreground = #ffbbbb
stderr-background = #111111
console-foreground = #ff4444
console-background = #111111
context-foreground = #ffffff
context-background = #444444

My current ~/.pystartup is short (in python2 it was much longer, since nothing worked right), just some common imports and functions I use enough to miss:

import os, sys
import math
import random as R
import re
import time
import turtle as T

def dice(n, s):
    t = 0
    for i in range(n):
        t += R.randint(1, s)
    return t

def roundup(n):
    return math.floor(n+0.5)

def sign(i):
    if i > 0: return 1
    elif i == 0: return 0
    return -1

print("READY")

Now if I click the foot and see “READY” above >>>, it’s all working.

What I’m Not Watching: Umbrella Academy

Trying to watch Umbrella Academy, and it is so slow. The assassins are more fun than the “family”, and they’re in maybe 5 minutes per ep.

Two of the siblings are absolute monsters who should be drowned; exiling the tiny-headed gorilla to the Moon to fill sandbags until he dies was a good plan, but letting the two-faced mindbender, low-rent Kilgrave ripoff that she is, walk around loose and unmuzzled is just stupid. Doesn’t help that I find both their actors/walking meatsticks stiff and incompetent, very obviously hitting marks and reading lines on a stage. Fire whoever hired these assholes.

Of the actual actors, Diego’s an acceptable Daredevil/Batman/Punisher ripoff, but nothing new at all. The junkie necromancer would be fun, but played so broad and silly he’s completely out of place in grimdark brooding land. “I waxed my ass with pudding!” is not a thing junkies say, dumbass writer. Normal girl who actually plays violin and writes is the only person in the family and she’s beat down and useless; and Ellen Page has aged into a mousy little thing. Number Five is good, fucked up but interesting; that’s the only positive reason to keep watching.

This bullshit of a CGI/robot ape butler and “mom” in an otherwise modern-tech universe is infuriating. If “dad” had AI and robotics that look exactly like real people or CGI animals, then he was already a superhero, didn’t need six superhero kids. The entire world would be very different. It’s like the Stepford Wives: You can solve world labor problems, bring about total prosperity and leisure for everyone… you use it to make one robot slave woman and keep going to bullshit job. Unsurprising, then, that the time traveller’s “woman” isn’t real, either.

And there’s 37 other superheroes out there supposedly, zero mention of them by ep 3.

I’d like to see more of the time travel plot, and the assassins, but I don’t think I can sit thru these fuckers whining at each other for hours.

★★☆☆☆