Sunday, May 12, 2013

Application Architecture Considerations


Here's a list of things I consider when evaluating an application's architecture:

Functionality

Does the application satisfy its business requirements?

Performance

Does the application run fast enough?

For example, if there are any views that take longer than 7 seconds to display, then you need to re-engineer something.

Scalability

How well does your application scale?
  • Can you easily add and remove components without affecting your application's performance or reliability?
  • How loosely (or tightly) coupled is your application code?

Messaging

  • How robust is the message bus/messaging framework?
  • How does your application handle events?

Memory Management

Does your application architecture provide memory management/garbage collection mechanisms?

Testability

How easy is it for developers to test features of your application, e.g., memory management or use case functionality?

Error Handling

How does the application handle errors and exception cases?

Logging

How does the application handle logging of normal and/or exception cases?

Consistency

Does the application code look like somebody cared or written by a disparate group of developers with their own styles and whimsical coding techniques?

Extensibility

How easy is it to extend the functionality of the application?

Reusable Components

How well does the application make use of reusable components?

Security

Does the application handle security?
  • Data Security
  • User authentication
  • Authorization
  • Accounting/logging of Security Events

Maintainability

  • How many lines of code does your application require to satisfy its functional requirements?
  • How readable is your code? (Fancy one liners that are unreadable add to technical debt.)
  • How defect-free is the application?
  • How long does it take to add functionality give new enhancement requirements?


Destructured Assignment: Another Case for CoffeeScript

Often times, a single options parameter is passed into a JavaScript function.

In that called function, we will then split up the options argument into separate variables to used later.

Javascript

Here's how it's frequently done in Javascript:


var options;

options = {
  id: 1,
  name: "bob",
  address: "123 main street",
  city: "new york",
  state: "ny",
  zip: 10027
};

({
  myFunction: function(options) {
    var address, city, id, name, state, title, zip;

    id = options.id
    name = options.name
    title = options.title
    address = options.address
    city = options.city
    state = options.state
    zip = options.zip;

    return console.log('name', name);
  }
});


CoffeeScript

Here's how it can be done in CoffeeScript:


options =
  id: 1
  name: "bob"
  address: "123 main street"
  city: "new york"
  state: "ny"
  zip: 10027
  

myFunction: (options) ->
  { id, name, title, address, city, state, zip } = options  # << Destructured Assignment
  console.log 'name', name


The CoffeeScript implementation, using Destructured Assignment is a nice improvement.



Javascript 1.7

Granted Javascript 1.7 provides Destructured Assignment, but if you rely on that, then you'll need to worry about end user browser compatibility and the higher likely hood of developers falling into the trap of using proprietary extra non-cross-browser features, e.g., Mozilla's for each.

Conclusion

This is one small example of why you should be using CoffeeScript instead of raw Javascript.

Here are a few more reasons to use CoffeeScript:
  • Fewer lines to write and maintain
  • More expressive (easier to understand) code
  • String interpolation
  • Consistent, readable, pretty-printed generated Javascript
  • Generally runs faster than typical Javascript hard-coded "equivalent" code


References

http://jashkenas.github.io/coffee-script/
http://js2coffee.org/


Friday, May 10, 2013

Rails Generate Controller Commands

Typical Rails Generate Controller Command

Rails generate commands are great for cranking out boilerplate code that you can later go back and customize.

Here, I create a Rails Controller and associated files...


$ be rails g controller Application index static
Rails.env: (development), using rails_env: (development)
    conflict  app/controllers/application_controller.rb
Overwrite /hs/dev/find-activities/api-fa/app/controllers/application_controller.rb? (enter "h" for help) [Ynaqdh]
       force  app/controllers/application_controller.rb
       route  get "application/static"
       route  get "application/index"
      invoke  erb
      create    app/views/application
      create    app/views/application/index.html.erb
      create    app/views/application/static.html.erb
      invoke  test_unit
      create    test/functional/application_controller_test.rb
      invoke  helper
   identical    app/helpers/application_helper.rb
      invoke    test_unit
      create      test/unit/helpers/application_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/application.js.coffee
      invoke    scss
      create      app/assets/stylesheets/application.css.scss



Rails Destroy Controller Command

I decided that I did not want the test files. So, I removed all the files that were generated

$ be rails d controller Application index static
Rails.env: (development), using rails_env: (development)
      remove  app/controllers/application_controller.rb
       route  get "application/static"
       route  get "application/index"
      invoke  erb
      remove    app/views/application
      remove    app/views/application/index.html.erb
      remove    app/views/application/static.html.erb
      invoke  test_unit
      remove    test/functional/application_controller_test.rb
      invoke  helper
      remove    app/helpers/application_helper.rb
      invoke    test_unit
      remove      test/unit/helpers/application_helper_test.rb
      invoke  assets
      invoke    coffee
      remove      app/assets/javascripts/application.js.coffee
      invoke    scss
      remove      app/assets/stylesheets/application.css.scss



With No Test Files

Here, I generate the files without the test files.


$ be rails g controller Application index static  --no-test-framework
Rails.env: (development), using rails_env: (development)
      create  app/controllers/application_controller.rb
       route  get "application/static"
       route  get "application/index"
      invoke  erb
      create    app/views/application
      create    app/views/application/index.html.erb
      create    app/views/application/static.html.erb
      invoke  helper
      create    app/helpers/application_helper.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/application.js.coffee
      invoke    scss
      create      app/assets/stylesheets/application.css.scss

Monday, April 29, 2013

Interactive CoffeeScript from Command Line

Here's how to install the CoffeeScript interpreter and test a ternary operation.


$ npm install -g coffee-script
npm http GET https://registry.npmjs.org/coffee-script
npm http 200 https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/coffee-script/-/coffee-script-1.6.2.tgz
npm http 200 https://registry.npmjs.org/coffee-script/-/coffee-script-1.6.2.tgz
/usr/local/bin/coffee -> /usr/local/lib/node_modules/coffee-script/bin/coffee
/usr/local/bin/cake -> /usr/local/lib/node_modules/coffee-script/bin/cake
coffee-script@1.6.2 /usr/local/lib/node_modules/coffee-script
$ coffee -h

Usage: coffee [options] path/to/script.coffee -- [args]

If called without options, `coffee` will run your script.

  -b, --bare         compile without a top-level function wrapper
  -c, --compile      compile to JavaScript and save as .js files
  -e, --eval         pass a string from the command line as input
  -h, --help         display this help message
  -i, --interactive  run an interactive CoffeeScript REPL
  -j, --join         concatenate the source CoffeeScript before compiling
  -l, --lint         pipe the compiled JavaScript through JavaScript Lint
  -m, --map          generate source map and save as .map files
  -n, --nodes        print out the parse tree that the parser produces
      --nodejs       pass options directly to the "node" binary
  -o, --output       set the output directory for compiled JavaScript
  -p, --print        print out the compiled JavaScript
  -s, --stdio        listen for and compile scripts over stdio
  -t, --tokens       print out the tokens that the lexer/rewriter produce
  -v, --version      display the version number
  -w, --watch        watch scripts for changes and rerun commands

$ coffee
coffee> name = "Activities"
'Activities'
coffee> a = if name==\"Activities\" then true else false
repl:1:15: error: missing ", starting
a = if name==\"Activities\" then true else false
              ^
coffee> a = if name=="Activities" then true else false
true
coffee>



References

Little Book on CoffeeScript
http://dailyjs.com/2011/05/30/code-review-coffeescript/



Sponsor Ads(Please visit one if you liked this article. Thanks!)

Tuesday, April 23, 2013

Online Business Risk Mitigation

First, let's look at what makes a business risky and unattractive to merchant account underwriters.

  • No financial and processing history
  • Stored value sales and accounts
  • Open ended time of use
  • Long Settlement Lag Times
  • High (over $500) ticket sales
  • High risk industries (travel, gaming, adult, liquor, online dating, debt consolidation, credit repair, and bankruptcy attorney)
  • Annual Billing, Lifetime Memberships, retainers and aggregation

Groupon


Now, let's look at an example, Groupon.  Groupon's business model as explained in Groupon’s site: “Each day, Groupon emails its members one unbeatable offer on something great to do in your city. We offer consumers great values by guaranteeing businesses a minimum number of customers. If a certain number of people sign up, then everyone gets the Groupon offer. If that minimum isn’t reached, then no one gets it.”

Here's what the merchant account underwriter gleaned from Groupon's own business model explanation:

  1. Groupon is selling other businesses' products and services that are easily contacted by the consumers who can then negotiate a better deal than Groupon can offer.  
  2. Groupon has a lot of competition from other online companies like Amazon.com, Expedia and Priceline.
  3.  Groupon sells mostly discretionary products and services that are more difficult to market and sell.


Groupon has little bargaining power with providers and a low barrier of entry from competitors which makes its business model unsustainable and unattractive.

Merchant Account Assessment

Since merchant account providers are ultimately financially liable for merchant losses, their underwriting and risk management team carefully assess each merchant account.

Merchant account providers would be financially liable if a merchant sold a lifetime membership but then went out of business within a few months.

Merchant Account Providers can mitigate risk by several means:

  • Reserving a percentage of sales for a specified period of time in an FDIC insured bank account, during which time the merchant proves their credit worthiness
  • Requiring an upfront reserve deposit
  • Requiring a personal guarantee

Online Merchants Risk Mitigation

Online businesses can make improve their attractiveness by:

  • Adopting a viable business model
  • Building a processing track record of low number of charge backs
  • Providing better user experience than their competitors with innovation/better technology and customer care
  • Selling high quality products and services with satisfaction guarantees
  • Clearly communicating terms and conditions
  • Fast and efficient problem resolution processes

References

http://www.forbes.com/sites/panosmourdoukoutas/2012/08/14/groupons-problem/

http://publicintelligence.net/glossary-of-terms-related-to-payment-clearing-and-settlement-systems/


Sponsor Ads(Say Thanks! by clicking an Ad)

Saturday, April 13, 2013

Localize Currency and I18N String Interpolation

number_to_currency is new to Rails 3.2.13

I found it necessary to specify the currency format options for each locale, which I put in separate .yml files, but you can put all of them in one .yml file for testing.

Open the rails console and include the NumberHelper class

>> include ActionView::Helpers::NumberHelper
=> Object

>> number_to_currency(1234567890.506)
=> "$1,234,567,890.51"

>> number_to_currency(1234567890.506, :locale => :en)
=> "$1,234,567,890.51"

>> number_to_currency(1234567890.506, :locale => :en_gb)
=> "1,234,567,890.51 £"

>> number_to_currency(1234567890.506, :locale => :fr)
=> "1 234 567 890.51 €"

>> number_to_currency(1234567890.506, :locale => :br)
=> "R$  1.234.567.890,51"

Locale yml File(s)


en:
  hello: "Hello world"
  hello-you: "Hello %{name}!"
  inbox:
    counting:
      one: You have 1 new message
      other: You have %{count} new messages
      zero: You have no messages  
  greetings:
    hello: "Hello"
    hey: "Hey"
  number:
    currency:
        format:
          significant: !'false'



fr:
  hello-you: "bonjour %{name}!"
  number:
    currency:
      format:
        format: "%n %u"
        unit: "&euro;"
        delimiter: " "
        

en_gb:
  number:
    currency:
      format:
        format: "%n %u"
        unit: "&pound;"

br:
  number:
    currency:
      format:
        format: "%u %n"
        unit: "R$ "
        delimiter: "."
        separator: ","


String Interpolation

You can build your I18N strings dynamically, assuming your .yml locale file is setup properly.

>> I18n.t("hello-you", {name: "John Doe"})
=> "Hello John Doe!"

>> I18n.t("inbox.counting", {count: 10})
=> "You have 10 new messages"

>> I18n.t(["greetings", "hello"])
=> [{:hello=>"Hello", :hey=>"Hey"}, "Hello world"]

>> I18n.t("hello-you", {locale: :fr, name: "John Doe"})
=> "bonjour John Doe!"

References

http://webdesign.about.com/od/localization/l/blhtmlcodes-cur.htm
https://github.com/fnando/i18n-js
https://github.com/jquery/globalize


Sponsor Ads(Say "Thanks!" by clicking the Ad below)

Thursday, April 11, 2013

What Makes a Single Page Web Application Scalable and Robust?


I'll start off by describing what I consider not scalable and robust.... A monolithic web application, where all of its resources (css, javascript, etc) are loaded and stay loaded from the entire life of the application instance.

So, one thing that would make an enterprise web application scalable and robust is the capability of loading and unloading portions of the application as appropriate to reduce resource, e.g., memory, consumption. It's very possible to a region of the window from the user's view, but have all of it, or portions of it remaining around in memory because there is still a reference that is holding on to it, e.g., a javascript object, html elements, etc.

  • Memory Management

4/12/2013

I'm back with another key element of a scalable/robust application...

The ability of one application component to publish messages to the message buss and for other components to listen/subscribe to those events and subsequently act on them.

  • Messaging Bus


Keeping logic for one area of concern in on module or several submodules, each with their singularly particular purpose.

  • Modules and Sub Modules


Decoupling the responsibility of one component from others.

  • Encapuslation


A dispatcher that directs interactions between the Model and View layers.

  • Controllers


I'll come back to this page to add more later.

Request for Information

In the meantime, what else can you think of? (please post in comments)

Sponsor Ads(Say Thanks! by clicking the Ad below)