JavaScript Modularity Shaming

David Nolen has made a compelling argument against “Modularity Shaming” – that is, rejecting a library or tool for being too bloated with features and not being modular enough. He argues that the main thinking behind Modularity Shaming is that the resultant production code also becomes bloated with needless dependencies, leading to poorer UX as users need to download more kb of data. The JavaScript community has come up with a couple of approaches to this problem, namely:

  1. Asynchonously load the JS library modules you need
  2. Use smaller libraries (e.g. Zepto as opposed to jQuery)

However, this problem can also be solved by using the Google Closure Compiler, a tool developed by Google for optimizing large JavaScript code bases such as the Google Closure library. It offers more advanced optimizations than the usual approach of minifying and concatenating JS code, in particular Dead Code Elimination aggressively strips out any code not being used by your application. In his post David gives a date time example with internationalization support built on Google Closure in 4kb of gzipped code, whereas the equivalent code using Moment.js would weigh at least 40kb.

In the original thread David links to where the term “Modularity Shaming” was coined, commenters raised additional concerns about how the batteries-included approach leads to documentation issues and “bitrot”, but on a technical level the Google Closure Compiler gives us a solid foundation to build large-scale web applications on.

Link

PyCharm Education Edition 1.0.1

PyCharm Educational Edition

JetBrains has just released an update to their recently released Pycharm Educational Edition. This is a Python IDE designed for programmers new to Python or just programming in general. It combines existing functionality from PyCharm such as the integrated Python console, debugger, and code inspectors with educational features such as code exercises and guided courses.

A noteworthy feature of 1.0.1 is a newly added “Introduction to Python” course which can be selected from the startup dialog. This course covers the basics of Python such as variables, flow control, and classes. The new release also has an improved experience for answering code exercises and allows cancelling the test check to avoid hanging on infinite loops.

If you’re just looking for a Python IDE without the educational features, PyCharm Community Edition is a great choice for a standalone Python IDE, and existing IntelliJ IDEA users can also consider installing PyCharm as an IDEA plugin.

Link

Prefer data over functions

Eric Normand over at LispCast has a great post detailing his thoughts on why data should be preferred over functions, which in turn should be preferred over macros. If you’ve done functional programming in a Lisp before, you may have run into the design issue of whether to model your problem in terms of functions or data. For instance, let’s say you want to calculate the average of a set of numbers. You could easily do it in Clojure with functions:

(def numbers [1 2 3 4])
(/ (apply + numbers) (count numbers)) ; => 5/2

Alternatively, you could model it by creating a mini-DSL – custom data structures which are passed to an interpreter function to produce a result:

(def expression [:div [:add numbers] [:count numbers]])
(calculate expression) ; => 5/2

In this case, using functions gets the job done much faster, and is easier to understand. However, Eric argues why you might prefer using data:

  1. Structure of the data is transparent at runtime, allowing it to be inspected and analysed
  2. Data can be manipulated easily – most Lisps have a rich set of functionality for dealing with data structures
  3. Data can be interpreted in different ways
  4. DSLs allow a simpler semantic model to be imposed – this is usually the reason for writing a DSL in the first place and makes it easier to write custom tools such as editors

Eric pragmatically ends the discussion with his own personal guideline that code should be written as functions first, and then refactored to data only when the problem domain has been well understood. This helps to prevent cases where the DSL has to be extended in all kinds of clunky ways, because the problem domain expanded or was not covered adequately.

Link

core.async for Asynchronous Programming

If you’re looking for a new language to try, Clojure is a particularly powerful option to pick. It’s a modern Lisp that can run on the JVM, JavaScript and .NET. This means that you can leverage the power and reach of an existing mature ecosystem – from full-stack web applications to desktop applications with Swing or NodeJS, and even writing games in Unity3D or Android.

To whet your appetite, here are a couple of videos on core.async, a Clojure/ClojureScript library for asynchronous programming that implements Communicating Sequential Processes (CSP) – a concept popularised by the Go language. Using channels and message-passing, CSP offers an elegant way to deal with concurrency and event handling without falling into callback hell.

It’s an indication of the power of Lisp macros that CSP can be implemented as a library without special support from the compiler, on top of both the JVM and JavaScript (which inherently does not support the multi-threaded style of programming).

If you’d like to check out Clojure further, I recommend this interactive course from the University of Helsinki. Clojure for the Brave and True by Daniel Higginbotham is another great place to start.

core.async for Asynchronous Programming

PostgreSQL 9.4 released

PostgreSQL coffee art by Yuko Honda
Yuko Honda

PostgreSQL, an object-relational database system, has just reached version 9.4. This stable release brings with it a host of new features, the most notable of which is JSONB support:

With the new JSONB data type for PostgreSQL, users no longer have to choose between relational and non-relational data stores: they can have both at the same time. JSONB supports fast lookups and simple expression search queries using Generalized Inverted Indexes (GIN). Multiple new support functions enable users to extract and manipulate JSON data, with a performance which matches or surpasses the most popular document databases. With JSONB, table data can be easily integrated with document data for a fully integrated database environment.

With the new JSONB data type, PostgreSQL is continuing to blur the line between it’s own relational database roots and NoSQL documented-oriented databases such as MongoDB and CouchDB. It remains to be seen whether more shops will adopt PostgreSQL for JSON storage since MongoDB still retains a more developer-friendly API, but at the very least it should spur greater competition among documented-oriented database systems.

Other features of this release include improvements to replication via the new Logical Decoding feature which allows API access to the PostgreSQL replication stream making it easier to write replication tools, and performance improvements in several areas such as GIN indexes.

More technical details on 9.4 features can be found on the wiki, while migration compatibility is documented in the release notes.

Link

Mochi

IMG_1112
Debbie Tingzon

Mochi is a new functional programming language written by Yasushi Itoh that runs on the Python interpreter. It supports actor-style concurrency and many features found in functional programming languages, such as:

  • Persistent vector and map data structures
  • Tail call optimization
  • Macros
  • Pattern matching (like switch statements on steroids)
  • Pipeline operator for threading functions together
  • More powerful syntax for creating anonymous functions than Python’s lambda
  • Lazy sequences

Compared to other built-on-Python languages I’ve seen such as Hylang and Pixie whose goal is to get Lisp running on Python, Mochi stays closer to the original Python syntax. One of the examples in the documentation shows creating a HelloWorld Flask app that is almost identical to the original Python version.

This strategy of creating a new language on top of an existing one has been used to powerful effect by languages such as CoffeeScript/Sass for front-end web development, and Clojure/Scala for backend services, allowing a new language to leverage the existing ecosystem of a more mature language. By offering persistent data structures and actor-style concurrency, Mochi itself looks targeted at building web services as well. Looking forward to seeing where Mochi goes in the future.

Link

Client-side coding: How to prevent malicious use?

A recent question asked on Programmers Stack Exchange was how to prevent misuse of an API exposed to a client-side application. The general consensus is that code running on the client-side should never be trusted, and should only be meant for enhancing the user experience. Any requests sent from the client should be validated by the server, even if they were validated on the client already.

In the original question, the scenario was how to send out an email from the client-side via a third-party service. Since the client should not be talking directly to the third party (and should never hold an API key for the third party in the first place), this operation should take place by sending a request to the server, which in turn validates the request and sends it to the third-party service.

(via Ars Technica)

Link

Go 1.4 released with preliminary Android support

Go, a programming language developed by Google, has just reached version 1.4. One of the milestones achieved by this release is support for writing simple Android apps:

The most notable new feature in this release is official support for Android. Using the support in the core and the libraries in the golang.org/x/mobile repository, it is now possible to write simple Android apps using only Go code. At this stage, the support libraries are still nascent and under heavy development. Early adopters should expect a bumpy ride, but we welcome the community to get involved.

At the moment however, the mobile APIs offered are centered around OpenGL and sprite-drawing, making it more suitable for writing games. In the long run, Google plans to support the NDK API, which means that it will not be a complete replacement for Java, but can be useful for writing native code in a safer and more productive language than C++.

According to the documentation page, iOS support is planned as well.

If you have not tried out Go before, it is a statically typed, garbage-collected language that arose from Google’s experience in writing and maintaining large code bases. SoundCloud engineer Peter Bourgon has a good teaser post that in a couple of hours goes from Hello, World! to a concurrent service aggregating data from two separate Weather APIs. For an overview of the Go language, I recommend this free e-book from Karl Seguin, and then there’s the official documentation as well.

Link

Jan 19: Algorithms: Design and Analysis, Part 1

Stanford has a new session of their Coursera algorithms course starting on the 19th of next month. Topics covered include asymptotic analysis, Quick Sort, Shortest-Path Finding, and data structures.

This course has been well reviewed and can act as a refresher even for those who have a strong CS background, or a friendly introduction to the tools you need to solve computational problems efficiently.

edit: Princeton has also announced a new session for Algorithms, Part I starting on 23rd Jan. This course covers a lot of the same material, but has a more practical approach and is focused on Java.

Link

objc.io issue #19 – Debugging

objc.io #19 – Debugging

objc.io, a magazine which takes an in-depth look into iOS development topics, has released their latest issue on the topic of debugging. Be sure to check out the first article, a case study on a bug report which begins innocuously but ends up with identifying a bug in UIKit (found via disassembly) and filing a radar to Apple, all the while stepping through the process of using the various debugging tools and references at your disposal.

Link