5 ms·
An iOS App in Assembly (2014)
- jacobush 9y agoAs I have seen too many times to be surprised now, the source code and setup in assembly is much easier in asm than in higher level languages. Look for ”COM programming with assembler” if you are curious. No casting, no bullshit. Just numbers pushed around :)
- yoz-y 9y agoI dunno. The massive amount of comments necessary to make this code remotely understandable is pretty telling.
- _sdegutis 9y agoAnd in one file there was a magic number #1536 or something, never got explained.
- tomsmeding 9y agoOof, that would have been hard. ;) More seriously, the "rule against magic constants" makes sense in many circumstances, but there are limits.
- exikyut 9y agoExplanation in the form of breadcrumbs: 1. https://github.com/kliment/Printrun/issues/619#issuecomment-102119718 https://github.com/kliment/Printrun/issues/619#issuecomment-... then 2. https://github.com/gnustep/libs-corebase/blob/master/Headers/CoreFoundation/CFString.h#L78 https://github.com/gnustep/libs-corebase/blob/master/Headers...
- bluedino 9y agoIt's more explaining how the whole OS X application model works than the code itself.
- exikyut 9y agoOkay, I got curious, but unfortunately that exact book title doesn't seem to exist.
- FraKtus 9y agowhat is more interesting is his other project to make an application in pure C: https://github.com/richardjrossiii/CBasediOSApp https://github.com/richardjrossiii/CBasediOSApp. When you are doing cross-platform, you may be more at ease with a few lines of C for some utilities call if you don't want to learn objective C.
- 52-6F-62 9y agoWhoa that looks so much simpler to me than ObjC. Of course I'm being a little naive because I haven't looked for moment at what those headers contain or how the API works, but just the same—that C version looks clean. I wonder what developing a more complex application would look like.
- delinka 9y agoI don't think it looks "simpler" than ObjC. He's still making the ObjC method calls, but with even more verbosity. I'd abstract all that away into macros or function calls ... but then you're right back to ObjC.
- tzahola 9y agoHe just de-sugared [foo bar] into objc_msgSend(foo, sel_getUid(“bar”))
- 0x0 9y agoAnd probably lost a ton of compiler assisted type checking in the process. I hope nobody considers doing anything remotely like this for any reason beyond learning a little about the low-level Objective-C machinery.
- tzahola 9y agoIt’s definitely NOT cross-platform. He’s just calling the objective-c runtime from C.
- drb91 9y ago
- mmjaa 9y agoDisclaimer: There are truly some madmen in the world. Thought: I LOVE THIS! I would love to see a few more even more complicated examples .. wouldn't it be neat if it turns out that its easier to write apps in Assembly than Swift/ObjC, lol ..
- ashleyn 9y agoIt's a cool stunt, but nothing more. The days of using assembly language in everyday business applications are long gone. Questions of portability immediately come to mind, as well as productivity losses relative to other companies/developers who are producing code faster and more efficiently.
- anta40 9y agoWell, never estimate the power of "hobby". When announcing Linux 27 years ago, Torvalds said "just a hobby, won't be big and professional like gnu". Now name any device and probably someone has ported Linux to it. In a similar way, probably old-school asm programmers will gather to write mobile app framework in assembly. You know, HTML/JS/Java/Swift is for sissies. Of course I'm kidding :p
- jcl 9y agoTrue, if you're writing a typical app, it will probably be easiest for you if you write it in the same manner as most other people. But if you are doing something very new or unusual, a sample project like this can be invaluable, since it shows the exact set of system calls needed for an app and roughly the minimal code. This is useful if, for example, you're trying to make a new language framework run on iOS (like Swift, Kotlin, or Rust), or if you're trying to answer questions like, "How much of an app's size is unavoidable?"
- biesnecker 9y agoEveryone that says "but it's insane to use assembly to write an iOS app!" is both 100% correct and 100% missing the point. It's nice to float around on the surface most of the time and ship useful code, but if you don't spend at least a little of your time digging deep you'll miss out on a lot. I'd never try to do this in prod, and neither would OP, but it's great to see how it works under the hood.
- anfilt 9y agoI know some people might not like this idea, but I feel more production systems should use some assembly. Although everything is a bit much. Also of the mindset we should be using more domain specfic languages.