Wednesday, October 12, 2011

Clojure will not work

Clojure will not work. Here is why it will not work.

Based on:

Programming Language Checklist

by Colin McMillen, Jason Reed, and Elly Jones.

Slightly modified for clearer rant

You appear to be advocating a new:
[x] functional  [ ] imperative  [x] object-oriented  [ ] procedural [ ] stack-based
[ ] "multi-paradigm"  [x] lazy  [ ] eager  [ ] statically-typed  [x] dynamically-typed
[x] pure  [ ] impure  [ ] non-hygienic  [ ] visual  [ ] beginner-friendly
[ ] non-programmer-friendly  [x] completely incomprehensible
programming language.  Your language will not work.  Here is why it will not work.

You appear to believe that:
[ ] Syntax is what makes programming difficult
[x] Garbage collection is free                [ ] Computers have infinite memory
[ ] Nobody really needs:
    [ ] concurrency  [ ] a REPL  [x] debugger support  [ ] IDE support  [ ] I/O
    [ ] to interact with code not written in your language
[ ] The entire world speaks 7-bit ASCII
[x] Scaling up to large software projects will be easy
[x] Convincing programmers to adopt a new language will be easy
[x] Convincing programmers to adopt a language-specific IDE will be easy
[ ] Programmers love writing lots of boilerplate
[ ] Specifying behaviors as "undefined" means that programmers won't rely on them
[ ] "Spooky action at a distance" makes programming more fun

Unfortunately, your language has (checked only *unfortunate features*, Clojure has tail recursion):
[ ] semicolons  [ ] significant whitespace  [x] macros
[x] implicit type conversion  [ ] explicit casting  [ ] type inference
[ ] goto  [x] exceptions  [ ] coroutines
[x] reflection  [ ] subtyping  [ ] operator overloading
[ ] algebraic datatypes  [ ] recursive types  [ ] polymorphic types
[ ] covariant array typing  [ ] dependent types
[x] infix operators  
[ ] call-by-value  [ ] call-by-name  [ ] call-by-reference  [ ] call-cc

Unfortunately, your language lacks:
[ ] comprehensible syntax  [ ] macros
[ ] implicit type conversion   [ ] type inference
[ ] goto  [ ] exceptions  [ ] closures  [ ] tail recursion  [ ] coroutines
[ ] reflection  [ ] subtyping  [x] multiple inheritance  [ ] operator overloading
[ ] algebraic datatypes  [ ] recursive types  [ ] polymorphic types
[ ] covariant array typing  [ ] monads  [ ] dependent types
[ ] infix operators  [x] nested comments  [x] multi-line strings  [ ] regexes
[ ] call-by-value  [ ] call-by-name  [ ] call-by-reference  [ ] call-cc

The following philosophical objections apply:
[ ] Programmers should not need to understand category theory to write "Hello, World!"
[ ] Programmers should not develop RSI from writing "Hello, World!"
[ ] The most significant program written in your language is its own compiler
[x] The most significant program written in your language isn't even its own compiler
[ ] No language spec
[x] "The implementation is the spec"
   [ ] The implementation is closed-source  [ ] covered by patents  [ ] not owned by you
[ ] Your type system is unsound  [ ] Your language cannot be unambiguously parsed
   [ ] a proof of same is attached
   [ ] invoking this proof crashes the compiler
[ ] The name of your language makes it impossible to find on Google
[x] Interpreted languages will never be as fast as C
[ ] Compiled languages will never be "extensible"
[ ] Writing a compiler that understands English is AI-complete
[ ] Your language relies on an optimization which has never been shown possible
[x] There are less than 100 programmers on Earth smart enough to use your language
[ ] ____________________________ takes exponential time
[ ] ____________________________ is known to be undecidable

Your implementation has the following flaws:
[x] CPUs do not work that way
[ ] RAM does not work that way
[ ] VMs do not work that way
[ ] Compilers do not work that way
[x] Compilers cannot work that way
[ ] Shift-reduce conflicts in parsing seem to be resolved using rand()
[x] You require the compiler to be present at runtime
[x] You require the language runtime to be present at compile-time
[x] Your compiler errors are completely inscrutable
[ ] Dangerous behavior is only a warning
[ ] The compiler crashes if you look at it funny
[x] The VM crashes if you look at it funny  (see example below) 
[ ] You don't seem to understand basic optimization techniques
[ ] You don't seem to understand basic systems programming
[ ] You don't seem to understand pointers
[ ] You don't seem to understand functions

Additionally, your marketing has the following problems:
[x] Unsupported claims of increased productivity
[ ] Unsupported claims of greater "ease of use"
[ ] Obviously rigged benchmarks
   [ ] Graphics, simulation, or crypto benchmarks where your code just calls
       handwritten assembly through your FFI
   [ ] String-processing benchmarks where you just call PCRE
   [ ] Matrix-math benchmarks where you just call BLAS
[x] Noone really believes that your language is faster than:
    [x] assembly  [x] C  [x] FORTRAN  [x] Java  [x] Ruby  [ ] Prolog
[ ] Rejection of orthodox programming-language theory without justification
[ ] Rejection of orthodox systems programming without justification
[ ] Rejection of orthodox algorithmic theory without justification
[ ] Rejection of basic computer science without justification

Taking the wider ecosystem into account, I would like to note that:
[ ] Your complex sample code would be one line in: _______________________
[ ] We already have an unsafe imperative language
[ ] We already have a safe imperative OO language
[ ] We already have a safe statically-typed eager functional language
[ ] You have reinvented Lisp but worse
[ ] You have reinvented Javascript but worse
[ ] You have reinvented Java but worse
[ ] You have reinvented C++ but worse
[ ] You have reinvented PHP but worse
[ ] You have reinvented PHP better, but that's still no justification
[x] You have reinvented Brainfuck but non-ironically

In conclusion, this is what I think of you:
[x] You have some interesting ideas, but this won't fly.
[ ] This is a bad language, and you should feel bad for inventing it.
[ ] Programming in this language is an adequate punishment for inventing it.

examples

"The VM crashes if you look at it funny":
user=> (defmacro re2 [x] (str "a" ~x))
#'user/re2
user=> (re2 1)
java.lang.IllegalStateException: Var clojure.core/unquote is unbound. (NO_SOURCE_FILE:0)
(only few people on Earth understand this error and actually no one of them understands why this error is not presented by compiler while defmacro)

Tuesday, October 11, 2011

New Python simple http request library

Where

http://docs.python-requests.org/en/latest


What and why

A successful attempt at simplifying HTTP requests in python.
Full support for cookies, headers, HEAD method and sessions (use of with block).
Code looks simple and clean (can't think of better complement).


Code example

>>> r = requests.get('https://api.github.com', auth=('user', 'pass'))
>>> r.status_code
204
>>> r.headers['content-type']
'application/json'
>>> print r.cookies
{'requests-is': 'awesome'}

Hooks

There are hooks available. One can have a function called pre-request or post-request.
http://docs.python-requests.org/en/latest/user/advanced/#event-hooks


Recommendations

This library is used internally at Twitter

Friday, September 16, 2011

No plugins in IE10 in Metro (smartphone) mode

http://www.infoq.com/news/2011/09/Metro-Plug-ins

Microsoft's IE 10 in Metro (smartphone) mode will not feature any plugins (not even Silverlight). It will only work with HTML5.

Actually this means that Silverlight is dead and Flash is rapidly drowning, despite late iPhone success.

Tuesday, July 19, 2011

The Baseball of Greed

Apple deals massive patent blow to HTC, Android in serious trouble | ZDNet

All right, there you have it. Patents just made Android die. Did it? Well.. at least in the US.

Now Europe has it's chance to outgrow USA technically. We don't have absurd laws that let one company basically smash other legitimate business with a Baseball of Greed.

Now I'll never buy anything from Apple not only for bad usability and aesthetic reasons, but also for moral ones. Any Apple user is from now on an enemy of free market!

Tuesday, July 5, 2011

Static hard typing is useless is method signatures

Consider following interface method signatures:
AlfaRomeoTargetProduct getByPK(java.lang.Integer languageVersionId, java.lang.Integer alfaRomeoId);

SigmaOmegaTargetProduct getByPK(java.lang.Integer sigmaOmegaId, java.lang.Integer languageVersionId);

And several other such getByPK methods. These were generated by O/R Mapping software. They are parts of the same application and are used together.

I've just spend at least half an hour looking for reasons for code below to explode:

...
case SIGMA_OMEGA_TEASER_OBJECT_TYPE:
productId = sigmaOmegaTargetProductDAO.getByPK(myObjectId, lvId, true).getProductId();
break;

case ALFA_ROMEO_OBJECT_TYPE:
productId = alfaRomeoTargetProductDAO.getByPK(myObjectId, lvId).getProductId();
break;
...

Until I checked the actual O/R Mapping code for getByPK.

For quirky reasons order of method attributes is shifted between various objects - sometimes languageVersionId is first, sometimes last.

Guess what? It should have been:

productId = alfaRomeoTargetProductDAO.getByPK(lvId, myObjectId).getProductId();

Static hard typing haven't prevented this error. I could be writting this code in dynamic language and save a lot of time.

It get's worse..

Let's suppose method signatures are fixed and myObjectId is always first and there is one more attribute lvId.

With language like python or ruby we could just ommit the switch/case structure and write:

dao = getDaoByName('alfaRomeoTargetProduct')
productId = dao.getByPK(myObjectId, lvId).getProductId()

We can't in java. Unless all of these O/R Mapping objects were using the same interface. Which is unsupported in O/R Mapping we use. So sad..

Moral: Static hard typing is useless. Even if no errors/inconsequences are present, static hard typing is counterproductive.

Monday, May 30, 2011

Want TextMate for Linux? Use kate!

Let's go through TextMate features with Kate in mind:

Ability to Search and Replace in a Project

That Eclipse-like goodie is actually better left to really powerful bash > find | sed && awk scripts. Otherwise you hit a wall rather sooner than later.

Auto-Indent for Common Actions Like Pasting Text

That of course is simply wrong thing to do. Usually one needs to guess what editor did and fix it manually. But kate has it of course if you insist.

Auto-Pairing of Brackets and Other Characters

Kate has it. Emacs has it. Vim has it. Basic prerequisite for any programming text tool.

Clipboard History

That would be cool. Oh wait, KDE has that..

Column Selections and Column Typing

Impressive but totally useless.

Completion of Words from Current Document

Kate has it.

CSS-like Selectors to Pinpoint the Scope of Actions and Settings

What? You know local scope for programming language you didn't know existed? How?

Declarative Language Grammars for Graceful Mixing and Hacking

Kate has it and even more. It has API for scripting: http://docs.kde.org/stable/en/kdesdk/kate/plugins.html

Dynamic Outline for Working With Multiple Files

Kate is also very good with multiple files.

Expand Trigger Words to Code Blocks With Tab-able Placeholders

You should avoid programming language that needs this feature often. You'd be better off. Actually doing that breaks DRY principle - you should add a method/macro to your code instead of repeating it.

File Tabs when Working With Projects

Tabify Kate pluging

Foldable Code Blocks

Classic. Kate has it.

Function Pop-up for Quick Overview and Navigation

This is actually better than in Kate. I miss it.

Plug-able Through Your Favorite Scripting Language

As said above, Kate is scriptable both from KDE and via Kate plugins.

Recordable Macros With No Programming Required

As iMacros prooves it, this is wrong path. Macros needs programming to be useful. Otherwise they just break DRY principle as above.

Regular Expression Search and Replace (grep)

I'd bet my money Kate has world-class support for regexp (positional, grouping) here. I've changed original text:
    * Ability to Search and Replace in a Project
    * Auto-Indent for Common Actions Like Pasting Text
    * Auto-Pairing of Brackets and Other Characters
to HTML H4 headers:
<h4>Ability to Search and Replace in a Project</h4>
<h4>Auto-Indent for Common Actions Like Pasting Text</h4>
<h4>Auto-Pairing of Brackets and Other Characters</h4>
By replace
    \* (.*)
with
<h4>\1</h4>

Run Shell Commands from Within a Document

Sure, type them without readline, without Ctrl+R history? Useless.

Support for Darcs, Perforce, SVK, and Subversion

Cool names. What do they do? Oh, you mean syntax highlihting? Kate has it. As for subversion: Integrating code revision control systems into text editor takes from you the power of text console. If you don't like console, you should work on it.

Support for More Than 50 Languages

Only 50?

Switch Between Files in Projects With a Minimum of Key Strokes

Kate beats strokes with one stroke (Alt+arrow).

Themable Syntax Highlight Colors

Kate has it.

Visual Bookmarks to Jump Between Places in a File

That is killer feature of Kate. It actually made me think TextMate is somewhat based on Kate.

Works As External Editor for (s)ftp Programs

With kate -u switch (use existing kate instance) you get to work on any project incredibly fast.

Works Together With Xcode and Can Build Xcode Projects

Cool, but I like both make and maven for a build system.

Wednesday, May 4, 2011

Encoding video with subtitles for playing on Xbox 360

mencoder HSE_0720.avi \
    -sub HSE_0720.srt -subfont-text-scale 3 -utf8 \
    -o HSE_out.avi \
    -of lavf -lavfopts format=asf -ovc lavc -lavcopts vcodec=wmv2 \
    -oac lavc -lavcopts acodec=wmav2 

It encodes any video playable with mplayer so that it is playable on Xbox (via uShare or Media Center).

Subtitles are rendered into video stream, so output .avi is standalone.