Smart Mobile Studio
  • News
  • Forums
  • Download
  • Store
  • Showcases
    • Featured demos
    • The Smart Contest 2013, Round 1 – Graphics
  • Documentation
    • Get the book
    • System requirements
    • Prerequisites
    • Getting started
      • Introduction
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • Themes and styles
    • Project types
      • Visual project
      • Game project
      • Console project
    • Layout manager
    • Networking
      • TW3HttpRequest
      • TW3JSONP
      • Loading files
  • About

The elegance of Javascript

Posted on 24.09.2011 by Jon Lennart Posted in News and articles

Two year ago I used to laugh at Javascript, but the more I play with it these days, I find myself enjoying the experience. It cant be compared to Delphi on any level, but there are some features that just blows your mind. I find myself spending a lot of time in Besen, a javascript interpreter and bytecode compiler written in Delphi – just for the sheer fun of it.I like the way dynamic parameters (what we would call array of const) are implemented and that they remain hidden to the entrypoint. This allows you to do do a form of undercover overloading. Unless the method is aware of _the calling interface_ (not the other way around like we are used to) then it could support only a sub-set of the intended functionality. By patching the original function and chaining to it you basically can “emulate” overloading based on condition rather than explicit call. This opens up for some clever API designs.I love the ability to pick values based on conditions, but compacted into a single line without having to invoke a equating entity:[sourcecode language=”javascript”]someValue = (backwards ? (100-percent) : (percent-100)) + "%";[/sourcecode]Having said that there are some aspects of javascript that makes me ponder the collective wisdom of W3C. As a fail-safe i usually add an “if” section to thoughts like this, because otherwise mother nature will go out of her way to disprove me. I can only imagine the work of cleaning up after Netscape and Microsoft, trying to play ball with Opera while Webkit came sneaking in the back door.

Media mayhem

The factors are many, yet the organization of the latest HTML5 multimedia functions is neither fish nor foul. It’s not truly object(ive) in the C++/Delphi sort of way, nor is it linear like basic or old school pascal. It’s both, and none of them at the same time . which makes it difficult to set up generic rules that would apply everywhere in our object model. The only solution is to let go of what the W3C has marked as “legacy features”. Which is hard to do when they produce results so easily 🙂

Threading, security and overkill

Another feature that seems like overkill, is the javascript notion of threads (read: blue threads), referred to as web-workers in the W3C specs for HTML5 (actually better info on Apple’s docs for safari). Im not sure what i was expecting, but i was sort of hoping to use threads to crunch pixel data. You can do that, but you are unable to hook the reference since it runs in a different context.

  • All communication between a worker and the DOM is through a message pipe
  • The only datatype you can pass to and from is a blob
  • All bindings are late-binding
  • Worker code cannot reside in the main document

Thankfully I found a “loophole”, I’ll document it later – but it wont make it into OP4JS because it’s basically a hack. You can use TW3GlobalStorage (one of our classes) as a mirror cache for the data – and it’s actually faster than creating, populating and moving a blob into the thread context. Although it does require initialization ofcourse. But i suspect that loophole will be closed in the next release.

External references

  • Besen – SourceForge project page 
  • Web workers – W3C documentation
javascript
« Snippets and comments, simple but effective
Focus, callstack and recursive processing »

Pages

  • About
  • Feature Matrix
  • Forums
  • News
  • Release History
  • Download
  • Showcases
    • The Smart Contest 2013, Round 1 – Graphics
  • Store
  • Documentation
    • Creating your own controls
    • Debugging, exceptions and error handling
    • Differences between Delphi and Smart
    • Get the book
    • Getting started
      • Introduction
      • Local storage, session storage and global storage
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • pmSmart Box Model
      • Themes and styles
    • Layout manager
    • Networking
      • Loading files
      • TW3HttpRequest
      • TW3JSONP
    • Prerequisites
    • Real data, talking to sqLite
    • System requirements
    • Project types
      • Visual project
      • Game project
      • Console project

Archives

  • December 2019
  • December 2018
  • November 2018
  • July 2018
  • June 2018
  • February 2018
  • September 2017
  • April 2017
  • November 2016
  • October 2016
  • September 2016
  • April 2016
  • March 2016
  • January 2016
  • October 2015
  • September 2015
  • July 2015
  • April 2015
  • January 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • November 2011
  • October 2011
  • September 2011

Categories

  • Announcements (25)
  • Developers log (119)
  • Documentation (26)
  • News (104)
  • News and articles (16)

WordPress

  • Register
  • Log in
  • WordPress

Subscribe

  • Entries (RSS)
  • Comments (RSS)
© Optimale Systemer AS