Hacker News new | past | comments | ask | show | jobs | submit login
Try Objective-C (codeschool.com)
176 points by noinput on May 9, 2013 | hide | past | favorite | 61 comments



Very nice presentation, but it seems like this could benefit from an Emscriptened browser-based Objective-C compiler.

Fabrice Bellard's browser-based Linux boots in less time than this prints out "Hello, world!"


We're reusing the stuff we built for the Try iOS course we came out with late last year. I've looked into Emscripten for this and from what I saw it really wouldn't work with this course, although maybe I missed something?


You could always boot the VM with an image that contains the compiler and run there. If it truly does boot faster than the results take otherwise then you could move it all into javascript that way, and not have to worry as much about the infrastructure around it.


Looks like work has started on using emscripten with Objective-C code:

https://github.com/kripken/emscripten/pull/1162/files

Still, a long way to go.


Wow, this is totally awesome. This is my first time hearing about emscripten and I've been a Cocoa and JS programmer for about 9 years.

What are some of the coolest applications of emscripten?


Not sure if this qualifies as 'cool', but I used Emscripten to port parts of OpenSCAD to Javascript http://www.fabfabbers.com/openscad


PDF.js is used by Firefox to render PDFs in the browser.


PDF.js doesn't use emscripten, as far as I can tell.

For a recent example of emscripten, try this one from yesterday: https://news.ycombinator.com/item?id=5673356


Very cute. I did the first 9 challenges. I am rather worried though that you're teaching people that `NSLog(var)` is acceptable, because it's a horribly dangerous thing to do if var contains untrusted input.


A good solution to this is to use always use a debug-mode dependent macro for logging[1]:

#ifdef DEBUG

#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt),__PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)

#else

# define DLog(...)

#endif

Put that in your [Project]-Prefix.pch file to make it available globally. Aside from letting you log without fear, it gives you better performance in production, and you can get extra context for your output.

1: http://stackoverflow.com/questions/969130/how-to-print-out-t...


Yup, I agree with you, but I wanted to introduce referencing a variable before introducing formatted strings and placeholders. We actually went back and forth on this a couple times.


Huh? How so?


If the variable's value contains any format args, e.g. %s, then NSLog (or printf, or whatever string formatting function you're using) will look for another argument, which you didn't actually pass, so it starts looking at garbage stack values.

Besides causing incorrect output, this may crash your program, or potentially be a vector for an exploit.


Is there any reason NSLog doesn't filter input to escape these format args?


It can't. http://en.wikipedia.org/wiki/Uncontrolled_format_string:

"In particular, the varargs mechanism allows functions to accept any number of arguments (e.g. printf) by "popping" as many arguments off the call stack as they wish, trusting the early arguments to indicate how many additional arguments are to be popped, and of what types."

NSLog is similar; it has to trust its first argument to be consistent with the number and types of arguments actually passed to it.

If you call NSLog(x), but do not have complete control over the value of x, you cannot guarantee that.


Because it's the format string, which the programmer is supposed to control?

NSLog(untrusted); bad. NSLog("The user entered %s", untrusted); OK.


Because that would defeat the entire purpose of NSLog.



Sorry for the slow response times on the challenge submissions everyone. We only have so many Mac Minis running these things . We are looking into ways to speed it up


Have you considered ccache?

http://ccache.samba.org/

You could also roll your own in a very few lines of code. Maybe even have the output of the program, not the compiled code, be the content of the hashed file, assuming you aren't reading STDIN or anything like that from the user.


That's a really cool project! Definitely going to look into it for some of our more complicated courses, but for this course compilation is usually under a half-second so it's not the compilation that's slow (it's the way we are tearing down an entire VM after every submission, we are working on changing that now)


Ah. Maybe consider a FreeBSD jail with a union mounted filesystem if you can get away with using a non-Apple (GNUstep/GCC?) toolchain. The teardown on a jail is as fast as the chroot syscall. ;-)

Or even better, use ZFS snapshots as your sandbox. Copy on write kicks butt. See: http://vocalbit.com/article/402/freebsd-jails-using-zfs-and-...


Just one nitpick for an excellent comment. GNUstep/Clang would be the only way to get support for array, dictionary and number literals, as well as ARC.

GNUstep/GCC is possible, but you lose support for all of the above, blocks, and several other recent additions to the Objective-C language.


Very true. We really leaned heavily on the new literals and ARC in this course.


Looks like those Mac Minis are getting smoked right now, poor little guys. I can't load the page unfortunately to see myself, but could you use GNUStep to compile the examples on any flavour of box?


I know I feel so bad for them. We are working on some temporary fixes (including caching which as we all know is really easy to do) and changing the way we isolate the code submissions so we can get more throughput. GNUStep might be an interesting long term fix.


In challenge # 22 in level 4, I am getting an error :‘extern’ variable has an initializer; I have tried the running the show answer solution but to no avail.


FWIW, Git Real 2 is working nicely at my place. I'm at level 2 now, looks great so far!


Could you use GNU Objective-C on Linux VMs, e.g. on AWS or something?


I have to work on porting an iPad app to Java from a guy that didn't bother to use comments or any documentation and his idea of versioning system are a bunch of folders 1,2,3 for different components whose numbers dont always match up.

I'm afraid I've been scared off Obj-C for life now.


"a guy that didn't bother to use comments or any documentation and his idea of versioning system are a bunch of folders"

What does this have to do with the Objective-C language itself?


> What does this have to do with the Objective-C language itself?

Nothing except they had a bad experience using the language. It's like that time you ate a bunch of meatloaf right before coming down with the flu. It wasn't the meatloaf, but you still might never eat it again...


nothing at all. but it scared me off. like in highschool i had this german teacher who scared me off german because she was a massive bitch. not the language's fault, but i hate german now.


You hate X because of a completely-unrelated-thing-Y? Try acting like an adult.


Why don't you try acting like a human.


sometimes I really get annoyed over here because of stupid comments like yours. keep it to yourself!


I really like this, but I'll have to give it another try in a few hours after work when the HN rush subsides and gives the server some time to breathe/compile the challenges.


Good idea, and our minis thank you ;)


Yow, that backend compilation step taking 20 seconds makes this way less fun than it looks like it should be :-/


I repurposed the content in the course to produce a simple HTML version of the course here:

http://rubymaverick.com/try-objectivec-book/

The content is up on my Github and any pull requests would be welcome!

https://github.com/rubymaverick/try-objectivec-book


We've gotten the course back up and responding to submissions in a reasonable amount of time (2.5~ seconds as compared to 30~ seconds earlier).

Please form a single file line behind mietek ;)


Is there anywhere I can read about the mac mini backend for this? Sounds interesting.


Only one complaint from me: error messages. I realize this is probably a complicated problem, but on the other hand, can alienate beginners.

For example, on the first exercise, you're asked to write NSLog(@"Name"); When I did it, I first missed the semicolon, and got an error "expected ‘;’ after expression". Okay, fine and good, that makes sense. I added the semicolon and got "‘extern’ variable has an initializer" because I called NSLOG instead of NSLog. Even for a programmer, that's not a helpful error message...


Thanks for the examples, and I agree that error messages are super-important for beginners. We have written a bunch of code trying to "massage" error messages to be more helpful. I'll be adding these to the list, thanks!


Only getting 504s at the moment. Will try again later..


The Super Mario World theme is cool, although super ironic since Objective-C/iPhone is helping to displace the Nintendo Empire.


Very interesting. I started with Try iOS but getting an actual app together in Xcode proved more difficult than I thought, partly because Obj-C still felt so weird after only learning Java/C# during university.

I ended up buying the Big Nerd Ranch book (it's great!) on iOS programming, which also covered Objective C in more detail.


I wish I had this 7 years ago when I was first learning the language.


Is it just me or do I really have to answer to Moby-Dick trivia while coding Objective C?

On the 1st level, I couldn't progress unless I used 'Ishmael' as firstName and 'Moby-Dick' as lastName.


I clicked "Start Course" and was greeted with a 404 that took way too long to load on my 50 megabit connection.

/shrug

Oh well, I'm sure there are other sites out there.


It's running on Mac Minis dude, and they're getting hammered. Bookmark it and visit again later. That's what I'm doing. :)


I like the new Git course, but I still can't take the first one... maybe fix that first?


We see green across the board for all 3 git courses, if you're personally having problems with one of them you should head on over to http://codeschool.com/support and drop them a ticket. :)


the site is very slow loading next page after clicking submit... Also, no option to skip the stupidly easy levels.


I'm actually working on extracting all the content for just a plain HTML version so people who don't want to do all the challenges will have something to read (it's almost a books length of content)


it seems a nice place to start.


This seems fun. Unfortunately it is stuck at challenge 2 and takes about 2 minutes per compile.


Good stuff... I guess?

I still fail to see the appeal of learning a language with such extremely limited value (only works, has tools and adaptation on a certain lawsuit-happy gadget-vendor's OS).

Anyone? And what about principles? What about giving back to the community? Shouldn't hackers hacking away on the next big thing be using open technologies as open technologies was what enabled them to get hacking in the first place?


Politically I agree, but Objective-C is a better language than C++ or Java, and Cocoa is a better framework than the STL or the Java core libraries. That's before we get to the GUI experience. Learning it will make you a better programmer.


Since I became a convert to the "put your own VM in the frameworks and add a cute language for your core logic" kind of school of thought, I seriously cannot see the value in Obj-C and the Android/Java thing. I've been writing code in these environments for decades: I'm now seriously addicted to Lua.

2 years of Lua work, and I absolutely cringe with the idea of having to go back to Java/Obj-C/C++, in any context other than to push a bridge across the VM gap to some framework.

Its a smaller language, its lighter. It performs quite well, and can be put almost anywhere there is a lib.so file (so: everywhere). Choose what you want to link with, extend the external API's with Lua, and leave the whole problem of obscure languages for the young 'uns..

So, its not so much about my desire to pimp Lua, but my point is this: You can choose whatever language you want, actually, to develop a core host environment with, but use a very simple, sweet language for the majority of the work.


So creating apps for an OS that controls 40% of the market share is limited value?

Open source is good, but I don't condemn software that's closed source. I use OSX and dualboot Windows, for one.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: