An old Afgan story/Velha história Afegã (EN/PT)

“A man a women had a son, they decided to move to greener fields
, and eventually found a place where it was very beautiful
there a man rented a house to them. They lived well until one day
during the night a wolf went into their house and stole their son.
They wept, but eventually recovered and tried again, giving birth to a second son.
Soon after the child was born the renter visited them and congratulated
them. Bought were happy, until one day the wolf returned and stole their second
child.
Devastated they changed place, left that house and never returned, eventually had a third
child and although they weren’t in that green field they were safe has the wolf never returned.”

This is my remembering of a old story of writer Ayaan Hirsi Ali, that her
grandmother told her during her childhood. The lesson here is that greener
fields aren’t always the safest. The renter was the wolf. If you buy her
biography it will give you a better read.

“Um dia um homem e uma mulher tiveram o seu primeiro filho, felizes resolveram
mudar-se para um local mais belo, encontraram um local e um homem alugou-lhes
uma casa. Mais tarde enquanto dormiam um lobo entrou na casa e roubou-lhes o filho,
choraram e lamentaram-se mas eventualmente recuperaram. Tiveram o seu segundo
filho, felizes congratularam-se, o arrendatário visitou-os e congratulou-os pela
boa nova… Após algum tempo o lobo regressou, roubou o segundo filho,
lamentaram-se, choraram e resolveram mudar-se dali.
Em novo local que apesar de não ser tão belo encontraram segurança.O lobo não
apareceu.”

Este é um trecho da auto-biografia de Ayaan Hirsi Ali em que ela narra uma
história que lhe fora contada por sua avó. A lição a tirar daqui é que os
locais que parecem ser os mais belos nem sempre são os mais seguros. O
arrendatário era o lobo. Se comprarem a auto-biografia terão uma melhor leitura
desta história.

http://en.wikipedia.org/wiki/Ayaan_Hirsi_Ali
http://pt.wikipedia.org/wiki/Ayaan_Hirsi_Ali

Importance of measurement

Measurement is the first step that leads to control and eventually to improvement. If you can’t measure something, you can’t understand it. If you can’t understand it, you can’t control it. If you can’t control it, you can’t improve it.

– H. James Harrington

 

https://www.youtube.com/watch?v=parmTnIr3gE

Vim with a menu = NERDTree

Imagem vim the editor   NERDTree

 

Tabs:

Open tabs = t
next tab = gt , previous tab = gT

Window and file opening:

Open AND: split vertical = s , split horizontal = i
prepend the commands with g and you keep the focus on the NERDTree menu

Menu

Create file and whatever:

> (a)dd a childnode
  (m)ove the current node
  (d)elete the current node
  (c)opy the current node

= m -> file system menu
cd -> change to the dir of the selected node

Common “commands” for vim

:w -> save current window
:wq -> save and quit
:q -> quit
:qa -> close all and quit

Window resize splits

Height -> resize 100 OR by increment -> resize +10
Width -> vertical resize 100 OR by increment -> vertical resize +10

This should do… :-)

PHP NumberFormatter

These are results from NumberFormatter from PHP

in the command line:

php -r ‘$a = new \NumberFormatter(“en”, \NumberFormatter::CURRENCY_CODE); print $a->format(122).PHP_EOL;’

You should get

one hundred twenty-two

Or

 php -r ‘$a = new \NumberFormatter(“pt_PT”, \NumberFormatter::CURRENCY); print $a->format(11122).PHP_EOL;’

You will  get

11 122,00 €

Get the Currency code now

print $a->getTextAttribute(NumberFormatter::CURRENCY_CODE).”\n”;

EUR

Java, Scala

Reading about scala I could only be curious about it, went to read details about the language and how it works. I get the idea that this is happening:

PHP is moving in the Java style direction… (Not trying to compare anything.)

Java is moving into a simpler coding Groovy, Scala ( in some cases harder) has Gosling him self professed. Both languages are being used in the financial markets( scala 1, scala 2, scala 3, Groovy ) for trading algorithms and social network Twitter , LinkedIn, it is said that Actors in Scala are a great way for Async communication Akka.Actors is said to be even better. Would like to have seen this two years ago, could have used this instead of Perl for a daemon I wrote. Both Scala and Groovy can use imported Java code.

James Gosling:
http://www.theserverside.com/news/2240022782/James-Gosling-Interview-from-Basementcoderscom

“I like Scala, but my big problem is that the type theory has gotten really complicated. The language lawyers are driving the bus. It’s turning into something that journeyman developers and even people like me… I started getting into the Scala stuff and my head starts to spin and I go, “what?””

Some Scala comments.

http://www.schauderhaft.de/2010/12/05/is-it-bad-to-use-scala-as-java-with-a-more-concise-syntax/

http://www.infoq.com/news/2009/07/scala-replace-java

Notice:
Gosling is listed as an advisor at the Scala company Typesafe Inc.[13] and Strategic Advisor for Eucalyptus.[14]

Clearly I’m more curious about Scala http://twitter.github.io/scala_school/ although Groovy has company’s supporting it but at the moment I’m just looking and playing not using. Scala Puzzlers

Java and JavaFX

After working with JavaEE I had enough PHP is simpler to use. And then I went to JavaFX and it was truly a better experience building the simple app that I wanted.

It was really simple to design and build the application for what I wanted and found good online support and that is something excellent.

Here’s the code.
https://bitbucket.org/odnanref/fxproductwatcher/src

Since I couldn’t get PHP 5.5 to work in Windows XP I chose to use Java (had something done in Python but the language syntax is more strange to me). The code is commented if anyone wants details about Thread + Tasks and UI.

Java for PHP Developers

I have been working with Java for android and a Web application purely for entertainment. For long I have seen PHP adopt more and more “ideas” from Java so to make it easy for someone that knows PHP to get into java and vice versa I’ll make some easy generic associations. This is from a HTTP point of view to simplify the relations.

Note: I have some basic background on Java and C# (Mono .NET), also I have an understanding of the design patterns that you will see applied in Java and in PHP frameworks and that helps understand the logic faster between the different languages.

  1. In PHP Controllers are Controllers, in Java they are mostly represented by a Servlet. It’s similar to Symfony 2  and Zend Framework adoption for handling requests. (Also in the Java Servlet can provide routing in the service method but not very used according to the reading I have been doing and the web.xml handles more of those requests).
  2. In PHP Models are provided by Frameworks Zend Framework or Symfony also has them, in Java they are usually called Beans and they also take the role of “Services” witch is something that came up in Zend Framework 2 and Symfony 2 not knew but the concept in the framework has been more noticeable.
  3. Template in PHP is done using some one of the following (known to have more) Smarty, Twig, normal PHP + HTML. In Java it is done via “tags” in Javaserver Pages (JSP) the approach of Javaserver Pages + Tags + Controller (Servlet) looked a lot like the Symfony 2 approach. (or vice versa)
  4. HTTP Server Jetty (there is jetty for android) is a simple to use webserver built in java witch is simple to deploy and run you can print a hello world pretty fast with not much work with it. Apache/Nginx install + PHP + some DB still is faster to me since it actually has more documentation and isn’t so java centered.
  5. Build and dependency management tools Maven is a most simple way to manage and install dependency’s in Java just get some example pom.xml files to get your basics and understand the build process and it looks like composer (yes that thing that many criticize). Maven also can create standard working environments and run tests.
  6. A ORM known in PHP is Doctrine a similar ORM in Java can be Hibernate. Hibernate also supports config by Annotations.
  7. Configuration in PHP can be handled on whatever you want to use, in frameworks like Symfony 2 it’s known has app/config.yml in Zend Framework 1 it’s application.ini in Zend Framework 2 it’s TODO something it’s more of a users choice. Symfony 2 also supports Annotations (via Doctrine Annotations) for route config et all, but in Java the Spring Framework his what I know to have those quirks but the Annotations are built in the language the main configuration for web development is usually a web.xml file in a WEB-INF directory.
  8. Database connetions PDO is for PHP what JDBC is for Java for database connection
  9. Packaging WAR or JAR it’s Java package what was based for Phar files in PHP
  10. Unit testing in PHP can be PHPUnit and in Java it can be jUnit
  11. Routing requests If you are looking in a more annotation style configuration for routing requests look at this text from wikipedia JAX-RS: Java API for RESTful Web Services and Rewrite Engine

This is a somewhat generic way of comparing the two languages but what you can notice is that Java like PHP has some built around solutions built with the language but they are supplied by standard API has .jar files and like PHP it also has a very intense activity around and different solutions ( just to say maybe we shouldn’t criticize having a lot of frameworks as Matthew Weier O’Phinney says:

Second, I also think there’s space for multiple implementations of any given component. Often there are different approaches that different authors will take: one might focus on performance, another on having multiple adapters for providing different capabilities, etc. Sometimes having a different background will present different problem areas you want to resolve. As such, having multiple implementations can be a very good thing; developers can look at what each provides, and determine which solves the particular issues presented in the current project.

(this last quote was placed because of a lot of discussion I see in forums and mailing lists regarding standardization of the way the developer codes and the way the language is built. Nothing new was said but the discussion of the PHP group (fig) is “deja vu”.

Coding in Java…

Well it’s not that simple has in PHP… Small example you do a POST in PHP you could just $_POST["FormDemo"]["id"] , $_POST["FormDemo"]["name"] , in Java it follows the standards strictly and you can only handle key value pair posts. You can handle the PHP POST array format but that involves regular expressions for what I’ve seen not simple has in PHP.

In Java you get strings via HTTP and change it to the format you require, in PHP you get Strings or whatever and you rarely care and if you care much you can type cast the variable if it’s int, float or Array.

Integer.ParseInt(string) will be your friend for Integer values for the “what you may want”.

Map<String,String> KeyValue = new Map<String,String>();

http://www.vogella.com/articles/EclipseWTP/article.html

Build setup:

I started by using Eclipse + Eclipse Web development tools and jetty with basic code, then installed Maven and https://code.google.com/p/run-jetty-run/ plugin search for it in eclipse market I wasn’t thinking on hibernate but I wanted something more abstract to handle the database and I am using Doctrine in PHP so just searched for a ORM in Java and went with that one.

 

UPDATE:

PHP is simpler to use my issue with Java it’s not about the Type declaration I actually like that and sometimes wish that was better in PHP. I actually didn’t like the server setup requirements I started with jetty witch is very simple but the deployment using maven and all that… If I was coding pure PHP it would have been faster and simpler. Frameworks in Java allow you the basic to build “normal stuff” in a simpler way like “routes” et all. But in PHP you actually can get something like that in a more simpler way and faster by just coding. JavaEE at the just looks like over complicated for a simple web app solution.

Seguir

Get every new post delivered to your Inbox.