Re:Shell Scripting with Objective-C
by mpweiher on Sunday June 01, 2014 @08:26AM
(#7828930)
This is very cool! The amount of functionality in modern application frameworks like Cocoa is really amazing, and it is a shame that it tends to be ignored/inaccessible for scripting tasks.
This processes a single icon per call. The only dependency apart from AppKit (and obviously Objective-Smalltalk) is MPWDrawingContext, which I load via EGOS_Cocoa.
Re:Shell Scripting with Objective-C
by melling on Saturday May 31, 2014 @10:00PM
(#7827885)
Shell scripting usually means writing in your shells (e.g sb, csh, zsh) native script. The author is using it to mean small scripts that he runs in a shell, which is fine with me.
I'm starting to use Go for these sorts of things because it's really fast. I'd try objc but if I want to move my programs to a Linux server, I'm out of luck.
Re:Shell Scripting with Objective-C
by wtallis on Saturday May 31, 2014 @10:12PM
(#7827919)
You're not out of luck when it comes to using objc on linux, you just have to forgo a lot of the newer APIs. But if you're using it on a server, chances are you won't miss the GUI APIs that GNUstep lacks.
Re:Shell Scripting with Objective-C
by mrsteveman1 on Sunday June 01, 2014 @09:03PM
(#7831371)
Indeed, I had an entire server blog engine written in objc, I had it running quite well on a Mac VPS (Lion running on vmware on Xserves), that I intended to move over to a Linode.
But I wanted libdispatch, blocks, all the stuff in the newer objc runtime, etc. Back then that meant playing all sorts of games compiling a specific objc runtime (there's more than one outside of apple), in a specific order with other things from GNUstep, using clang at certain steps instead of gcc to compile it all. It was a mess, but if I had really wanted to I probably could have pulled it off, and now I'm sure things have improved. I moved the entire thing to python and forgot about it though.
But I've always liked the idea of writing little things that have no GUI of any kind in objc, I wrote a few commandline utilities in objc and loved it. Background services on the system (mac or linux either one) would be fun too I think.
Re:Shell Scripting with Objective-C
by 21echoes on Sunday June 01, 2014 @12:18AM
(#7828163)
To be a bit pedantic: NSImage isn't part of a GUI toolkit -- don't confuse NSImage with UIImageView! The NSImage is more equivalent to a .png, not to a web <img> tag; it's completely separate from a framework for routing data to the screen.
Re:Shell Scripting with Objective-C
by Moto7451 on Sunday June 01, 2014 @02:54AM
(#7828395)
NSImage is part of AppKit and while it is definitely key to a lot of UI code that's because of well thought out delegation rather than it being part of UIKit or CocoaTouch. It would be pretty annoying to have two different and possibly incompatible NSImage classes to deal with if it lived in each platform's UI framework.
Re:Shell Scripting with Objective-C
by bshimmin on Sunday June 01, 2014 @05:06AM
(#7828593)
This bit about summed it up for me:
"You can say that [NSJSONSerialization JSONObjectWithData:resultsData options:0 error:nil]; is more verbose than r.json() but verbosity is an Objective-C convention, for the better or the wors[e]"
For this sort of task, like one of the other commenters, I would almost certainly write something quick and simple (and fairly unstructured) in bash; if it needed to be more maintainable, I'd write it in Ruby. Using a verbose, static typed language just seems wrong here.
Of course, for any given programmer and any given task, using the language with which they are most familiar is often a very good option (obviously only in circumstances where it is possible to perform the task in that language and its specific attributes don't jeopardise the successful running of the task).
Re:Shell Scripting with Objective-C
by ant_sz on Sunday June 01, 2014 @01:23AM
(#7828253)
The objective-c with ARC support really enjoys some advantages script programing languages enjoy. Apple added many syntax sugar such as `@[]` to build array and `@{}` to build dictionary, which makes it easy to write.
So I am not surprised someone is trying to use it as a so-called shell script. The cocoa frameworks really contains a lot of convenient API (ex. when it comes to python, you have to install PIL or something else to process images). But on the other hand the objective-c shell scripting can not be used on platform other than OSX. That is a disadvantage.
Re:Shell Scripting with Objective-C
by jicea on Sunday June 01, 2014 @02:18AM
(#7828333)
Hi author here!
It was more a play experiment than a true try to replace Python/Ruby/Go scripting. I was very intrigued by "Objective-C Minimalism" http://bou.io/ObjectiveC-Minimalism.html and wanted to see what would be scripting in Objective-C with all new features (Objects literals, ARC etc...)
Re:Shell Scripting with Objective-C
by natch on Sunday June 01, 2014 @10:18AM
(#7829203)
What is going on in the below line?
c = [t v]
Can you tell me what c represents, and where it got its value? Sure, from [t v], but what are those? No, you can't. You finished reading it really quickly, but you understand very little about what is going on.
"A lot more text" is there for a reason: to explain what is going on.
How about:
cellsToUpdate = [tableView visibleCells]
This code tells you exactly what each item means. I find clear naming really nice to work with. Not that I would necessarily use exactly that line as a way of doing things, but hopefully you get the idea.
Re:Shell Scripting with Objective-C
by shadesandcolour on Sunday June 01, 2014 @11:12AM
(#7829404)
I like Objective-C a whole lot, but this is a shitty example. You didn't show what "a lot more text" looks like, you showed everyone what "proper variable names" look like.
- didn't replicate the slugify
- dependencies: imagemagick, jq
- here without spaces: http://pastebin.com/yBPwHwdk
- to get the same clarity as the python & Obj-C samples, I'd probably be approaching the same length.
Here is an implementation in Objective-Smalltalk (http://objective.st):
This processes a single icon per call. The only dependency apart from AppKit (and obviously Objective-Smalltalk) is MPWDrawingContext, which I load via EGOS_Cocoa.(also, the pedant in me would like to point out that this is not "shell scripting" as you're not scripting a shell, but it's super cool regardless)
I'm starting to use Go for these sorts of things because it's really fast. I'd try objc but if I want to move my programs to a Linux server, I'm out of luck.
But I wanted libdispatch, blocks, all the stuff in the newer objc runtime, etc. Back then that meant playing all sorts of games compiling a specific objc runtime (there's more than one outside of apple), in a specific order with other things from GNUstep, using clang at certain steps instead of gcc to compile it all. It was a mess, but if I had really wanted to I probably could have pulled it off, and now I'm sure things have improved. I moved the entire thing to python and forgot about it though.
But I've always liked the idea of writing little things that have no GUI of any kind in objc, I wrote a few commandline utilities in objc and loved it. Background services on the system (mac or linux either one) would be fun too I think.
In this case, the GP is correct: NSImage is part of the UI toolkit (AppKit); it is not a core API exposed by, say, Foundation.
"You can say that [NSJSONSerialization JSONObjectWithData:resultsData options:0 error:nil]; is more verbose than r.json() but verbosity is an Objective-C convention, for the better or the wors[e]"
For this sort of task, like one of the other commenters, I would almost certainly write something quick and simple (and fairly unstructured) in bash; if it needed to be more maintainable, I'd write it in Ruby. Using a verbose, static typed language just seems wrong here.
Of course, for any given programmer and any given task, using the language with which they are most familiar is often a very good option (obviously only in circumstances where it is possible to perform the task in that language and its specific attributes don't jeopardise the successful running of the task).
So I am not surprised someone is trying to use it as a so-called shell script. The cocoa frameworks really contains a lot of convenient API (ex. when it comes to python, you have to install PIL or something else to process images). But on the other hand the objective-c shell scripting can not be used on platform other than OSX. That is a disadvantage.
It was more a play experiment than a true try to replace Python/Ruby/Go scripting. I was very intrigued by "Objective-C Minimalism" http://bou.io/ObjectiveC-Minimalism.html and wanted to see what would be scripting in Objective-C with all new features (Objects literals, ARC etc...)
"A lot more text" is there for a reason: to explain what is going on.
How about:
This code tells you exactly what each item means. I find clear naming really nice to work with. Not that I would necessarily use exactly that line as a way of doing things, but hopefully you get the idea.