News for hackers. Stuff that matters.
Re:Another go at the Next Big Language by viraptor on Monday September 03, 2012 @07:05PM (#4472189)
I think that putting it in the body actually reduces the amount of code and makes it more readable. Compare something like this (ignoring naming, formatting, made up language, etc. I want to show the structure only):

    fin=open(fin_name)
    fout=open(fout_name)
    ...
    catch IOError e
      if e.call == 'open'
        if e.filename == fin_name
          log_error "cannot open input ..."
        elif e.filename == fout_name
          log_error "cannot open output ..."
        else
          log_error "cannot open file, but filename unknown"
      elif e.call == .....
        .....
to something like this:

    try
      fin = open(fin_name)
    catch IOError
      log_error "can't open input ...."
      return

    try
      fout = open(fout_name)
    catch IOError
      fin.close()
      log_error "can't open output ...."
      return
Both are ugly, but I really wouldn't like to be the person trying to match up the error handling from the first example to the exact places in the function body. I'm not even sure what would this look like if the exception was coming from somewhere deeper in the function. open() is easy because we know how it fails. More complex call chains would be a challenge to even match up to the place they happened.

There are no comments on this comment yet.