Anic: Faster than C, safer than Java, simpler than *sh
code.google.com
code.google.com
Am I the only one who still has to google most of 'sh's predicates and syntax?
I like bash. Especially bash v4 brought some niceties, making it even more suitable for various non-trivial tasks.
I generally don't "upgrade" to Python or some "real" scripting language unless I really have to: bash is surprisingly concise and expressive. I've written programs and subroutines in bash that were much smaller than their idiomatic Python counterparts and I was surprised to discover that.
Bash is conceptually pretty safe and suits the functional mindset because in a large program you find you want to isolate each function the Unix way: byte streams. You pass in a stream (and args) and you get a stream out (and exit status). Thus, you end up making the functions quite pure and well off if you come from a functional background. Pure functions/shell scripts are rather safe and also parallelize pretty well.
If part of your program does something critical it's best to move it from a set of functions into a separate shell script. This gives you the same Unix stream API but also the benefit of process-level separation of data and environment. It simply enforces the Unix byte streams as the only way to talk between the caller and the callee.
And usually you can do this with only a few lines of code. Shell scripting can be ― and is ― intuitive. This is because processing files and streams, I/O, and parsing and mangling command lines and strings of words is pretty implicit in bash, which usually is very close to what you want to achieve in the end so you get down to the actual work pretty quick.
Having said that, I personally don't feel shellscripting is all that intuitive either.
Does anyone have to write shellscripts? If I'm writing one and it has any degree of complexity at all -- i.e. has loops or subroutines -- I just write it in Python. The only part of bash I know is the subset I use interactively on the command line.
Besides, init scripts aren't really portable (across distros) to start with, ubuntu/debian scripts rely on start-stop-daemon and a specific filesystem layout. The use of shell for init scripts is probably only useful because using dash (/bin/sh) to execute them is likely faster than using a fancier language (though I haven't benchmarked this).
BTW, ever try and write anything non-trivial using dash (POSIX shell features only). It's pretty painful. Lots of people mistakenly write shell using non-posix (bash) features, and are unpleasantly surprised when /bin/sh links to dash, thus breaking their scripts.
I'm also familiar with object pipelining shells from using powershell.
ANI looks like an unreadable mess to me.
I wouldn't feel the same way if it was a different sh than bash. For example, this is easy in bash:
let total=0
let n=10
for ((i=0; i<n; ++i)); do
if (( i % 2 != 0 )); then
printf 'Odd: %.3d\n' $i
fi
let total+=i
done
echo "Total is: $total, average is $((total / n))"
Staying inside bash, you only have integer arithmetic, but that's sufficient for many problems. The major advantage is that you can easily, and more importantly, readably, compose solutions using programs written in dozens of different languages. The syntax for piping programs together in scripting languages tends to be imperative, rather than declarative like a shell script.I just don't do enough of it to make it in to an automatism.
let total=0
let n=10
for ((i=0; i<n; ++i))
do
if (( i % 2 != 0 ))
then printf 'Odd: %.3d\n' $i
fi
let total+=i
done
echo "Total is: $total, average is $((total / n))"The next example is a little better, I still have no idea what it means but at least it looks like I possibly might once I've read the docs (which I will do now).
Once you read the basic tutorial, the language is not hard to read.
Yes, indeed. You might also like Haskell and Clean that also do this.
> and parallelization of your code for you
And may soon do that as well.
It just comes off as odd at first because it's dealing with concepts that are actually pretty unique (to my knowledge at least) - streams and latches.
US keyboards have an extra-big left shift, and a small return key, with the backslash and pipe above the return. UK (and as far as I'm aware, most other Eurpopean) keyboards have a small left shift with the backslash and pipe key just to the left of the Z. The return key is nice and big, hard to miss. The button above the return is the backspace, also nice and big and hard to miss.
(And annoyingly, every single Linux installation I have ever used has mis-mapped the Dvorak translation of the key to the left of the Z, mapping it to < and >, rather than \ and |. I often have to faff about with loadkeys layouts and xmodmap layouts for several hours every time I do a new install.)
*added ä and ö keys, as they are needed in finnish.
I really hope its a joke.
On the other hand, (having read the tutorial) it does seem to be interesting concept that could be helpful in some fields.
Pitty it's so poorly marketed. I hope they change that after it becomes a usable product.
Of course, the real barrier to using this for real projects would be library support.
I'll contribute something to you, in return: if you're interested in graph-based audio/visual programming, check out vvvv for Windows. It's like Processing, but visual (i.e., designed via UI), and very very fast. It was made by visual artists who actually use it to make big bucks, rather than computer science weenies.
Besides that, you may find the languages listed here interesting: http://stackoverflow.com/questions/461796/dataflow-programmi...
I've been playing around with dataflow concepts myself and personally see them as the way forward in programming, though I'm not quite sure yet how it would need to be done to catch on as a mainstream language. I think I'll play with anic for a bit and see what happens :)
These claims leverage the fact that the fastest implementation in C is incredibly difficult to write. Usually we discard that difficulty when comparing languages, but as time goes on the costs of developing specific distributed, multi-threaded, and/or reliable systems in pure C becomes so outrageous that it stops making sense to ignore, so we start comparing against less correct implementations.
I find that kind of claim pretty annoying.
backslashes were chosen for a purely pragmatic reason; on virutally all keyboards, backslashes are very easy to type (requiring only a single keystroke). This is a handy property for backslashes to have because in ANI, you'll be typing them a lot!
Many more examples contrasted with the equivalent imperative code.
Examples with elaborate data structures.
Implementation overview (current & objectives).
Benchmarks on a multicore.It does a much better job of explaining the language.
ANI seems to be quite an interesting language. I haven't looked at dataflow languages before, so this might be fairly standard.
The trivial answer is "Yes", but that answer raises two non-trivial and more interesting questions
1) If the language is faster than C, why write the compiler in C rather than natively compiling it (the acid test of a C compiler is if it can compile itself).
2) What computer languages are used to write computer languages?
I've created a "Ask HN" question for discussion http://news.ycombinator.com/item?id=1042398.
If you are implementing a language (for which you also have some say in its design) and your compiler is too slow, then I would start e.g. by investigating caching strategies instead of switching implementation languages.
Interesting! Any links? a quick google search didn't turn anything up.
About which are you talking? You confuse me.
When a developer has to wait for the compiler, he not only is waiting, but there are also secondary effects: he loses concentration, browses HN, talks to coworkers, etc. http://xkcd.com/303/
Probably the most the revolutionary thing about the Borland compilers, for instance, was that they compiled instantly compared to their competition.
You can do that in pretty much any language if you decide to. I'm not seeing the point here, and the syntax is just horrible.