Should I switch from EJS to Dust.js while using Kraken.js? - ejs

We have been developing a Express app with EJS as templating engine for sometime. After Kraken.js released its version for compatible with expressJS 4, I am given the task of migrating from express to Kraken. My app is not a MVC app. It is a view Model, gets all its data from another node.js server via restify.
I started researching on Dust.js which comes in default with Kraken.js. I am having a hard time trying to decide whether I need to switch my templating language from ejs to Dust. Some of things with regards to Dust.js that are relevant to my app are:
It is a less logic templating engine. I can easily switch the templating engine in the future
I really only care about Client side templating
It can be used for asynchronous rendering( not sure if it can be on the client side)
It has partials both static and dynamic
It has helper methods which can help with logic. It has for loops, math etc
My question is I was able to do all the above with EJS. Why do I need to switch to Dust.js? What advantages does Dust.js bring with respect to EJS in the context of Kraken.js?

It is not inherently necessary to use dust with kraken. PayPal uses dust and has, therefore, built a lot of infrastructure around it, but if you have no need for those bits of functionality, using any other templating language is all the same (save the fundamental difference between those templating languages).
As for what you gain by using dust with kraken: the simplest explanation is localization. A couple of modules in the krakenjs stable of monsters presently have a hard dependency on dust. Namely, engine-munger (specialization and l18n), makara (l18n—largely superseded by engine-munger), and adaro (an express dust renderer). Some modules leverage dust if that's in use (bundalo, for one, puts things into the dust cache on your behalf) or expose first-class support for dust (kraken-devtools which handles environment specific asset compilation; e.g., compiling assets on the fly in dev vs with a build step on prod).
All said, if you don't need to use the supported method for internationalization, you won't necessarily lose anything. You may end up having to write some of your own infrastructure if you want to use certain things like kraken-devtools or karka, but those are definitely not insurmountable issues.

Related

Rest APIs in Go - using net/http vs. a library like Gorilla

I see that Go itself has a package net/http, which is adequate at providing everything you need to get your own REST APIs up and running. However, there are a variety of frameworks; the most popular maybe say gorilla.
Considering that one of the main things I need to do going forward is to build REST APIs that will access some back-end storage (databases, caches, etc.) to perform CRUD operation, is it good to go with Go's standard library itself, or should I consider using some frameworks?
Normally, people write a new library or framework which solves the problem present in the existing library. But a lot of the frameworks also tend to make things worse when actual demands are simple.
So I have few questions:
Is the basic library in go lang good enough to support basic to moderate functionality for REST?
If I do end up using the inbuilt library and tomorrow have to change it to use some framework (like a gorilla), how difficult/costly would that be?
Are frameworks really addressing the problems or just making simple problems complex?
I would be extremely grateful for someone to share his thoughts here (who has been through making this choice himself) while I research more of my own.
The net/http package is probably sufficient for most scenarios, but if you want to ease your development, you should use a third-party package, such as Gorilla.
For example, net/http's ServeMux does a great job at routing incoming requests for fixed URL paths but for pretty paths which use variables, you will need to implement a custom multiplexer while using Gorilla, you are getting this for free.
Another example is if you want to specify RESTful resources with
proper HTTP methods, it is hard to work with the standard
http.ServeMux, while with Gorilla's mux package,
requests can be matched based on URL host, path, path prefix,
schemes, header and query values, and HTTP methods.
One of the great benefits of Gorilla is that it is fully compatible with the net/http package and can be substituted in the future.
See 1.
I totally encourage you to use Gorilla's toolkit to develop REST services.
The built-in net/http package is sufficient to build a complete REST API. However, some of the libraries can make building an API slightly easier, particularly if the REST API is complex. Changing from the built-in facilities to any decent framework is relatively straightforward - they generally accept handlers of the http.Handler type.
In the end, though, this is an extremely situational choice. The best thing you can do is examine each available solution, contrast and compare, and build a proof of concept with the top options if you possibly can. First-hand experience will guide you best.

Does Perl have RIA frameworks like zkoss or Vaadin in Java?

I am new to Perl. I would like to know if Perl has RIA (Rich Internet Application) frameworks like zkoss or Vaadin or GWT from Java?
How do Java and Perl compare in terms of memory management and pattern design?
RIA
In short, no. But take a look at the Catalyst Framework.
But no, I don't know anything as glossy and point&click-y as "zkoss" or "vaadin". HTML+CSS+Perl works fine as well, if you know them.
Memory Management
Perl is a garbage collected. Variables that are no longer referenced get freed. Beware that in general, Perl tends to prefer time efficiency over memory efficiency what does not mean that perl is in any way bloated. Also beware, that circular references have to be manually broken, or the garbage collector won't be able to detect those variables to be collected. That is somewhat unlike Java.
Patterns
Yes, of course you can use any patterns you like. Perl doesn't make objetc orientation too easy by default, however the Moose Framework helps with that. Whith Perl, you can also use some functional patterns like closures or currying that are not available, or not as easily available, in Java. Note that Anonymous Classes get really hard to create with Perl, but hard things are still possible. You often don't need them anyway with closures.
Good Literature
See the info page of the "perl" tag on SO: https://stackoverflow.com/tags/perl/info especially the free books section. I like Higher Order Perl, although reading through the basics first should be sensible.
The Perl documentation with perltoot, perlboot and other pages has good introductions to traditional Perl object orientation techniques, which differ superficially from the Moose interface.
Try Sencha Ext JS:
http://www.sencha.com/products/extjs/
There is even a Perl package available to boot:
RPC::ExtDirect - https://metacpan.org/pod/RPC%3a%3aExtDirect
From http://www.sencha.com/products/extjs/
What is Sencha Ext JS?
Sencha Ext JS is the leading standard for business-grade web
application development. With over 100 examples, 1000 APIs, hundreds
of components, a full documentation suite and built in themes, Ext JS
provides the tools necessary to build robust desktop applications. Ext
JS also brings a rich data package that allows developers to use a
model-view-controller (MVC) architecture when building their app. The
MVC leverages features like Big Data Grids enabling an entirely new
level of interactivity in web apps.
Modern App Framework
Ext JS 4 is a major step forward for web frameworks. Building on Ext
JS 3.3, our latest release adds over 350 new APIs, 50 new classes, and
65% more documentation. An entirely new data package equips developers
to leverage features like Infinite Grid Scrolling to build an entirely
new level of interactivity to web apps.
From https://metacpan.org/pod/RPC%3a%3aExtDirect
Abstract
This module provides an easy way to map Perl code to Ext.Direct RPC
interface used with Ext JS JavaScript framework.
What Ext.Direct is for?
Ext.Direct is a high level RPC protocol that allows easy and fast
integration of server components with JavaScript interface. Client
side stack is built in Ext JS core and is used by many components like
data Stores, Forms, Grids, Charts, etc. Ext.Direct supports request
batching, file uploads, event polling and many other features.
Besides simplicity and ease of use, Ext.Direct allows to achieve very
clean code and issue separation both on server and client sides, which
in turn results in simplified code, greater overall software quality
and shorter development times.
From Perl module developer perspective, Ext.Direct is just a method
attribute; it doesn't matter if it's called from Perl code or through
Ext.Direct. This approach, in particular, allows for multi-tiered
testing:
Server side methods can be tested without setting up HTTP environment with the usual tools like Test::More
Server side classes can be tested as a whole via Ext.Direct calls using Perl client
Major application components are tested with browser automation tools like Selenium.
For more information on Ext.Direct, see
http://www.sencha.com/products/extjs/extdirect/.

What is scaffolding? Is it a term for a particular platform?

Scaffolding, what is it? Is it a Rails-only thing?
Scaffolding generally refers to a quickly set up skeleton for an app. It's not rails-only since other platforms have it as well. It's also not generally meant to be a "final" system; merely the first, smallest way to do it.
From Wikipedia:
Scaffolding is a meta-programming
method of building database-backed
software applications. It is a
technique supported by some
model-view-controller frameworks, in
which the programmer may write a
specification that describes how the
application database may be used. The
compiler uses this specification to
generate code that the application can
use to create, read, update and delete
database entries, effectively treating
the template as a "scaffold" on which
to build a more powerful application.
Just like a real scaffolding in a building construction site, scaffolding gives you some kind of a (fast, simplified, temporary) structure for your project, on which you can rely to build the real project.
It can be (and is today) used to describe many things - from abstracting DB layers, to web apps folder structures, and to generating and managing project dependencies .
It is not something that is specific to any language / technology, just like the term skeleton or boilerplate is platform agnostic.
It is just a term borrowed from real scaffolding (like mentioned above).
You build some fast, simplified, (sometimes external, sometimes temporary) structure that will help you to build the real, more complex, finalized structure under, above, inside or outside of that temporary structure .
.. And just like the real scaffolding, the scaffolding structure is meant to support the building process of the project, rather than the project itself (with some exceptions).
Scafolding is usually some type of code generation where you point it at a database, and the technology creates basic CRUD (create, read, update, delete) screens.
I believe that Wikipedia and some answers here provides a narrow and restricted view. Scaffolding is not just for CRUD operations on top of a database. Scaffolding has a broader objective to give you a skeleton app for any kind of technology.
Yeoman is a modern and useful tool for scaffolding. Using their own words:
The web's scaffolding tool for modern webapps
What's Yeoman?
Yeoman helps you to kickstart new projects, prescribing best practices
and tools to help you stay productive.
To do so, we provide a generator ecosystem. A generator is basically a
plugin that can be run with the yo command to scaffold complete
projects or useful parts.
Through our official Generators, we promote the "Yeoman workflow".
This workflow is a robust and opinionated client-side stack,
comprising tools and frameworks that can help developers quickly build
beautiful web applications. We take care of providing everything
needed to get started without any of the normal headaches associated
with a manual setup.
With a modular architecture that can scale out of the box, we leverage
the success and lessons learned from several open-source communities
to ensure the stack developers use is as intelligent as possible.
As firm believers in good documentation and well thought out build
processes, Yeoman includes support for linting, testing, minification
and much more, so developers can focus on solutions rather than
worrying about the little things.
That's it. Use scaffolding to create a quick-start application to work as an example or the foundation of your solution. It makes you productive faster them building things from scratch.
It is not a rails only term although I think it originated there (at least that is where I first heard it.)
Scaffolding is a framework that allows you to do basic CRUD operations against your database with little or no code. Generally, you then go through and add the code to manage the data the way you want replacing the scaffolding. It is generally only intended to get you up and running quickly.
No it is used in other technologies also such as ASP.NET MVC
it creates a basic layout from some predefined code which programmers uses in almost every project , Eg: for database data access it can make a crud method for create, read, update, delete operations
OR you might use it to create layout for your View/Html Code
Scaffolding is writing any piece of code that would not be part of the business logic but would help in unit testing and integration testing.
This is a software engineering term and not bound to any framework or programming language.
No, scaffolding is not the term for the specific platform, however many know this term in the context of Ruby on Rails or .NET
There are also plenty of tools that perform javascript scaffolding:
divjoy.com
flatlogic.com
scaffoldhub.com
yeoman.io
Those tools are also known as code-generators
Scaffolding is the term used when you don't want to create all parts of the structure such as models, views, etc. and want to generate them all in one go. A lot of frameworks use this technique, I studied about it while doing odoo but most of the references given were to ruby on rails :)

Do you need a framework to write Ruby or Python code for the web?

Every time I see Ruby or Python discussed in the context of web development, it's always with a framework (Rails for Ruby, Django for Python). Are these frameworks necessary? If not, is there a reason why these languages are often used within a framework, while Perl and PHP are not?
I can only speak towards Ruby - but, no, you don't need a framework to run Ruby based pages on the web. You do need a ruby enabled server, such as Apache running eruby/erb. But, once you do, you can create .rhtml files just like RoR, where it processes the inline ruby code.
The short answer is no, they are not necessary. In ruby you have .erb templates that can be used in a similar way as you use PHP pages. You can write a site in ruby or Python using several technologies (Rails-like frameworks, Templates or even talking directly with the HTTP library and building the page CGI-style).
Web frameworks like Python's Django or Ruby's Rails (there are many) just raise the level of abstraction from the PHP's or ASP's, and automate several process (like login, database interaction, REST API's) which is always a good thing.
"Need" is a strong word. You can certainly write Python without one, but I wouldn't want to.
Python wasn't designed (like PHP was, for example) as a direct web scripting language, so common web-ish things like connecting to databases isn't native, and frameworks are handy.
EDIT: mod_python exists for Apache, so if you're merely looking to write some scripts, then Python doesn't need a framework. If you want to build an entire site, I'd recommend using one.
From a Pythonic point of view, you'd absolutely want to use one of the frameworks. Yes, it might be possible to write a web app without them, but it's not going to be pretty. Here's a few things you'll (probably) end up writing from scratch:
Templating: unless you're writing a really really quick hack, you don't want to be generating all of your HTML within your Python code -- this is a really poor design that becomes a maintainability nightmare.
URL Processing: splitting a URL and identifying which code to run isn't a trivial task. Django (for example) provides a fantastic mechanism to map from a set of regular expressions to a set of view functions.
Authentication: rolling your own login/logout/session management code is a pain, especially when there's already pre-written (and tested) code available
Error handling: frameworks already have a good mechanism in place to a) help you debug your app, and b) help redirect to proper 404 and 500 pages.
To add to this, all of the framework libraries are all heavily tested (and fire tested). Additionally, there are communities of people who are developing using the same code base, so if you have any questions, you can probably find help.
In summary, you don't have to, but unless your project is "a new web framework", you're probably better off using one of the existing ones instead.
Framework? Heck, you don't even need a web server if you're using Python, you can make one in around three lines of code.
As to the why:
The most plausible thing I can think of is that Perl and PHP were developed before the notion of using frameworks for web apps became popular. Hence, the "old" way of doing things has stuck around in those cultures. Ruby and Python became popular after frameworks became popular, hence they developed together. If your language has a good framework (or more than one) that's well supported by the community, there's not much reason to try to write a Web App without one.
A framework isn't necessary per se, but it can certainly speed development and help you write "better" code. In PHP, there are definitely frameworks that get used like CakePHP, and in Perl there are many as well like Mason and Catalyst.
The frameworks aren't necessary. However, a lot of developers think frameworks ease development by automating a lot of things. For example, Django will create a production-ready backend for you based on your database structure. It also has lets you incorporate various plugins if you choose. I don't know too much about Rails or Perl frameworks, but PHP frameworks such as Zend, Symfony, Code Igniter, CakePHP, etc are used widely.
Where I work at we rolled our own PHP framework.
Are these frameworks necessary?
No. They, like any 'framework', are simply for speeding up development time and making the programmer's job easier.
If not, is there a reason why these languages are often used within a framework, while Perl and PHP are not?
PHP and Perl were popular languages for building web sites well before the idea of using frameworks was. Frameworks like Rails are what gave Ruby it's following. I'm not sure that Python or Ruby were that common as web languages before they were backed by frameworks.
These days, even PHP/Perl web developement should be backed by a framework (of which there are now many).
By no means are those development frameworks required. But as with most development environments, your productivity will increase exponentially if you have a supported framework to reference and build your applications on. It also decreases the training needed to bring others up to speed on your applications if they already have a core understanding of the framework that you use.
For python, the answer is No you don't have to. You can write python directly behind your web server very easily, take a look at mod_python for how to do it.
A lot of people like frameworks because they supply a lot of the boilerplate code in a reliable form so you don't have to write it yourself. But, like any code project, you should choose the tools and frameworks on their merit for your problem.
You can certainly write CGI scripts in either language and do things "raw".
The frameworks (ideally) save the trouble of writing a pile of code for things that other people have already handled (session handling, etc.).
The decision probably comes down to what you need to do. If the framework has the features you need, why not use it. If the framework is going to require extensive modifications, it might be easier to roll your own stuff. Or check out a different framework.
The python library has numerous modules for doing cgi, parsing html, cookies, WSGI, etc:
http://docs.python.org/library/index.html
PHP has a lot of frameworks. Probably more then most. In Ruby most use Rails so thats what you hear, and Django for Python is mentioned more then not.
But with PHP you have many to choose from.
List of web application frameworks
Any language that can "print" can be used to generate web pages, but frameworks handle a lot of the HTML generation for you. They let you concentrate more on the content and less on the details of coding the raw HTML.

Suggestions for Adding Plugin Capability?

Is there a general procedure for programming extensibility capability into your code?
I am wondering what the general procedure is for adding extension-type capability to a system you are writing so that functionality can be extended through some kind of plugin API rather than having to modify the core code of a system.
Do such things tend to be dependent on the language the system was written in, or is there a general method for allowing for this?
I've used event-based APIs for plugins in the past. You can insert hooks for plugins by dispatching events and providing access to the application state.
For example, if you were writing a blogging application, you might want to raise an event just before a new post is saved to the database, and provide the post HTML to the plugin to alter as needed.
This is generally something that you'll have to expose yourself, so yes, it will be dependent on the language your system is written in (though often it's possible to write wrappers for other languages as well).
If, for example, you had a program written in C, for Windows, plugins would be written for your program as DLLs. At runtime, you would manually load these DLLs, and expose some interface to them. For example, the DLLs might expose a gimme_the_interface() function which could accept a structure filled with function pointers. These function pointers would allow the DLL to make calls, register callbacks, etc.
If you were in C++, you would use the DLL system, except you would probably pass an object pointer instead of a struct, and the object would implement an interface which provided functionality (accomplishing the same thing as the struct, but less ugly). For Java, you would load class files on-demand instead of DLLs, but the basic idea would be the same.
In all cases, you'll need to define a standard interface between your code and the plugins, so that you can initialize the plugins, and so the plugins can interact with you.
P.S. If you'd like to see a good example of a C++ plugin system, check out the foobar2000 SDK. I haven't used it in quite a while, but it used to be really well done. I assume it still is.
I'm tempted to point you to the Design Patterns book for this generic question :p
Seriously, I think the answer is no. You can't write extensible code by default, it will be both hard to write/extend and awfully inefficient (Mozilla started with the idea of being very extensible, used XPCOM everywhere, and now they realized it was a mistake and started to remove it where it doesn't make sense).
what makes sense to do is to identify the pieces of your system that can be meaningfully extended and support a proper API for these cases (e.g. language support plug-ins in an editor). You'd use the relevant patterns, but the specific implementation depends on your platform/language choice.
IMO, it also helps to use a dynamic language - makes it possible to tweak the core code at run time (when absolutely necessary). I appreciated that Mozilla's extensibility works that way when writing Firefox extensions.
I think there are two aspects to your question:
The design of the system to be extendable (the design patterns, inversion of control and other architectural aspects) (http://www.martinfowler.com/articles/injection.html). And, at least to me, yes these patterns/techniques are platform/language independent and can be seen as a "general procedure".
Now, their implementation is language and platform dependend (for example in C/C++ you have the dynamic library stuff, etc.)
Several 'frameworks' have been developed to give you a programming environment that provides you pluggability/extensibility but as some other people mention, don't get too crazy making everything pluggable.
In the Java world a good specification to look is OSGi (http://en.wikipedia.org/wiki/OSGi) with several implementations the best one IMHO being Equinox (http://www.eclipse.org/equinox/)
Find out what minimum requrements you want to put on a plugin writer. Then make one or more Interfaces that the writer must implement for your code to know when and where to execute the code.
Make an API the writer can use to access some of the functionality in your code.
You could also make a base class the writer must inherit. This will make wiring up the API easier. Then use some kind of reflection to scan a directory, and load the classes you find that matches your requirements.
Some people also make a scripting language for their system, or implements an interpreter for a subset of an existing language. This is also a possible route to go.
Bottom line is: When you get the code to load, only your imagination should be able to stop you.
Good luck.
If you are using a compiled language such as C or C++, it may be a good idea to look at plugin support via scripting languages. Both Python and Lua are excellent languages that are used to script a large number of applications (Civ4 and blender use Python, Supreme Commander uses Lua, etc).
If you are using C++, check out the boost python library. Otherwise, python ships with headers that can be used in C, and does a fairly good job documenting the C/python API. The documentation seemed less complete for Lua, but I may not have been looking hard enough. Either way, you can offer a fairly solid scripting platform without a terrible amount of work. It still isn't trivial, but it provides you with a very good base to work from.