Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Balancing Object-Functional Design Guided by Tests

1,759 views

Published on

When we think of OO, most people think of modeling THE real world in software by mapping every real world object (nouns) to entities in software. These entities are then modeled using Is-A-Has-A relationship to build complex, polymorphic hierarchies with deep object graphs. State is stored and mutated in-place inside the object to achieve the desired functionality. This paradigm leads to a fairly convoluted design and encourage imperative style of programming.

Not everyone who has designed large complex systems, think of OO the same way. For instance, people who Test Drive, do not have the luxury of a big-up-front design, instead they focus on small and incremental design. IME, TDD facilities a design that is side-effect free and encourages a declarative style of programming. While decoupling and composing objects in a functional style with the right granularity of abstraction.

Let's assume we've to build a web commenting and discussion feature (like Disqus). And we've a requirement to implement this as a jQuery Plugin. Can we apply pure functional principles to design this? Or will the design be better if we try a classical OO JS approach? In this live demo, we'll build this plugin from scratch and see how TDD will help us drive an object-functional design to strike a pragmatic balance between the 2 paradigms.

More details: http://confengine.com/functional-conf-2015/proposal/1462/balancing-object-functional-design-guided-by-tests

Published in: Software
  • Be the first to comment

Balancing Object-Functional Design Guided by Tests

  1. 1. Naresh Jain @nashjain http://nareshjain.com Balancing Object-Functional Design Guided by Tests
  2. 2. OO= Modelling Real World
  3. 3. …And soon
  4. 4. Classic Debate
  5. 5. OO Gets A Bad Name X
  6. 6. O O + F P + T D D T H I S W O R K S H O P I S A B O U T …
  7. 7. A G E N D A - 1 2 0 M I N S • Basic Setup (WebStorm, NPM, Jasmine, Karma, …) • Live Demo of Test Driving a Comments jQuery Plugin • Moving towards a • Monadic (MayBe) interface and • MVVM design pattern • Stubbing out AJAX calls • Next Steps…
  8. 8. W E P L A N T O B U I L D T H I S …
  9. 9. Add a Test Run the Test Make a little change Run the Test Refactor Fail Pass Fail Pass TDD Rhythm Test, Code, Refactor
  10. 10. B A S I C S E T U P • cd ~/projects • git clone git@github.com:nashjain/jQCommentDemo.git • cd jQCommentDemo • npm update • sudo npm install -g karma-cli • karma init • Create a Simple Jasmine Spec • run Jasmine Spec via karma test runner
  11. 11. Commercial Break!
  12. 12. Copyright © 2012,
  13. 13. Mumbai
  14. 14. Tech Talks!
  15. 15. O U R P L U G I N ’ S F E AT U R E S • Should be able to accept a comments json or an URL to fetch the comments json from server • Should display most recent comments on top • Private comments should be displayed only to the author of the comment • Others should be able to like your comment • and so on…
  16. 16. R E F E R E N C E S • https://learn.jquery.com/plugins/basic-plugin-creation/ • http://jasmine.github.io/2.3/introduction.html • https://github.com/velesin/jasmine-jquery • https://github.com/jasmine/jasmine-ajax • http://karma-runner.github.io/0.13/index.html
  17. 17. Naresh Jain @nashjain http://nareshjain.com Thank you!

×