Archive

Velocity is a Java-based template engine. It permits web page designers to reference methods defined in Java code. Basically, you can create files (HTML, XML, etc…) writing scripts and generate them following a template.

– Create Maven Project.

– Add dependency in your pom file – Change the version of the lib:

<dependency>

<groupId>org.apache.velocity</groupId>

<artifactId>velocity</artifactId>

<version>1.6.4</version>

</dependency>

– Create a Vm template, like this one. Save as .vm (I created outside the package test). So, place your template in Project > src > customer.vm and not with the code which the structure is: Project > src > package.test:

– Vm file is the template, you will create the template and what the variables that will have the value that you want.

– Inside Java Class:

You need initialize the Velocity API – Write the path of the vm template – Initialize the context and write all the variables and the values (name – variable, word – value) – Initialize the Writer which will render the template – Merge the context and the values creating the template – Show the result

– To run the project, first I had to compil with maven test and after this I just choose Run As – Java Application.

So, this is the first script, I will write more about, but between this you can have a look on the links below. See you guys 🙂

– Run this command to be sure that everything it is running correctly: mvn package

– Create a new class contains the list of “features” that make up the application, and stories related to each feature. These stories are not the tests themselves – rather they are used to model the application requirements.

What is functional programming? Everything is a mathematical function. Functional programming languages can have objects, but generally those objects are immutable — either arguments or return values to functions. There are no for/next loops, as those imply state changes. Instead, that type of looping is performed with recursion and by passing functions as arguments.

Functional programming requires that functions are first-class, which means that they are treated like any other values and can be passed as arguments to other functions or be returned as a result of a function. Being first-class also means that it is possible to define and manipulate functions from within other functions. Special attention needs to be given to functions that reference local variables from their scope. If such a function escapes their block after being returned from it, the local variables must be retained in memory, as they might be needed later when the function is called.

The following table shows which languages support functional programming (by supporting first-class functions) and for which the functional style is the dominant one.

Language

Closures

Functional

C

No

No

Pascal

No

No

C++

Yes

No

Java

Yes

No

Modula-3

Yes

No

Python

Yes

No

Ruby

Yes

No

Javascript

Yes

Yes

Ocaml

Yes

Yes

Erlang

Yes

Yes

Haskell

Yes

Yes

Benefits

Functional programming is known to provide better support for structured programming than imperative programming. It is easy, for instance, to abstract out a recurring piece of code by creating a higher-order function, which will make the resulting code more declarative and comprehensible.

Functional programs are often shorter and easier to understand than their imperative counterparts. Since various studies have shown that the average programmer’s productivity in terms of lines of code is more or less the same for any programming language, this translates also to higher productivity.

Object-oriented x Functional languages

When you anticipate a different kind of software evolution:

Object-oriented languages are good when you have a fixed set of operations on things, and as your code evolves, you primarily add new things. This can be accomplished by adding new classes which implement existing methods, and the existing classes are left alone.

Functional languages are good when you have a fixed set of things, and as your code evolves, you primarily add new operations on existing things. This can be accomplished by adding new functions which compute with existing data types, and the existing functions are left alone.

When evolution goes the wrong way, you have problems:

Adding a new operation to an object-oriented program may require editing many class definitions to add a new method.

Adding a new kind of thing to a functional program may require editing many function definitions to add a new case.

I have been reading about what is functional programming on the last weeks (Just because I was curious) and I found a lot of articles, but I summarized here a little piece of each place which helped me to better understand what really is.

If you are interested about functional programming you can click on this link. I found it very interesting and easy to understand.