It's even worse than it appears.
Sunday July 19, 2020; 11:15 AM EDT
  • This is a language design question, not a coding question.#
  • This bit of code comes up all the time.#
    • if (callback !== undefined) {#
      • callback ();#
      • }#
  • It would be interesting to try to come up with a clean way to say that so it would still be obvious what's happening, but would save you from having to check it so often.#
  • Basically I want to call the callback if the caller specified one, otherwise, do nothing. #
  • Just putting that out there, not offering a solution to the puzzle. #
  • Later...#
  • How about this syntax#
    • if possible callback ();#
  • Where possible might be a new keyword that's something like a try but not as serious. In other words, don't get upset if this doesn't work. On the other hand, it's not much more concise than the original expression, and it doesn't say anything about what you expect not to work about it. Really for anything other than undefined I probably want an error to be thrown so I can find the problem and fix it. #
  • I'm not an Applescript type person, I think programming can't be a spoken language, but I also don't go so far as to say programming is like linear algebra or differential calculus (both of which I took in college). I like words that mean something when I read them, both in human language and programming language.#
  • Another random thought, not a big fan of using let as a new kind of declaration. I imagine they chose it because that's what BASIC used, but why would a nice Algol-like language use BASIC as prior art. I actually like how we did it in Frontier:#
    • fileloop (f in "tmp/")#
      • local (fname = file.fileFromPath (f))#
      • file.rename (f, string.upper (fname))#
  • fname is only accessible in the body of fileloop. #
  • local is the keyword for declaration. It says fname is declared here, in this scope, and it is only accessible here. I think it does a better job of explaining itself than let. #
  • Even later...#
  • Allen Wirfs-Brock suggested via email, that JavaScript already has this feature, he sent a link to the docs, and I couldn't make heads or tails of it. I said how the hell do you pronounce that? That's where the comment about linear algebra and differential equations came from, above. #
  • Well he started a thread on Twitter asking how people pronounce this feature that as far as I can tell does not have a name? It's an instant classic of course. #

© 1994-2020 Dave Winer.

Last update: Sunday July 19, 2020; 5:39 PM EDT.

You know those obnoxious sites that pop up dialogs when they think you're about to leave, asking you to subscribe to their email newsletter? Well that won't do for Scripting News readers who are a discerning lot, very loyal, but that wouldn't last long if I did rude stuff like that. So here I am at the bottom of the page quietly encouraging you to sign up for the nightly email. It's got everything from the previous day on Scripting, plus the contents of the linkblog and who knows what else we'll get in there. People really love it. I wish I had done it sooner. And every email has an unsub link so if you want to get out, you can, easily -- no questions asked, and no follow-ups. Go ahead and do it, you won't be sorry! :-)