Category: programming

Java User-Friendness

I can’t see how people say Java is an end-user language, whose applications are for general user usage…

SEVERE: Exception
javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:302)
	at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
	at org.apache.fop.cli.Main.startFOP(Main.java:174)
	at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:501)
	at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
	... 3 more
Caused by: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.fop.events.ValidationExceptionFactory.createException(ValidationExceptionFactory.java:38)
	at org.apache.fop.events.EventExceptionManager.throwException(EventExceptionManager.java:54)
	at org.apache.fop.events.DefaultEventBroadcaster$1.invoke(DefaultEventBroadcaster.java:175)
	at $Proxy1.invalidChild(Unknown Source)
	at org.apache.fop.fo.FONode.invalidChildError(FONode.java:534)
	at org.apache.fop.fo.flow.Inline.validateChildNode(Inline.java:123)
	at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:267)
	at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
	at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
	at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
	... 4 more

---------

javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:501)
	at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
	at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
	at org.apache.fop.cli.Main.startFOP(Main.java:174)
	at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.fop.events.ValidationExceptionFactory.createException(ValidationExceptionFactory.java:38)
	at org.apache.fop.events.EventExceptionManager.throwException(EventExceptionManager.java:54)
	at org.apache.fop.events.DefaultEventBroadcaster$1.invoke(DefaultEventBroadcaster.java:175)
	at $Proxy1.invalidChild(Unknown Source)
	at org.apache.fop.fo.FONode.invalidChildError(FONode.java:534)
	at org.apache.fop.fo.flow.Inline.validateChildNode(Inline.java:123)
	at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:267)
	at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
	at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
	at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
	... 4 more
---------
org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.fop.events.ValidationExceptionFactory.createException(ValidationExceptionFactory.java:38)
	at org.apache.fop.events.EventExceptionManager.throwException(EventExceptionManager.java:54)
	at org.apache.fop.events.DefaultEventBroadcaster$1.invoke(DefaultEventBroadcaster.java:175)
	at $Proxy1.invalidChild(Unknown Source)
	at org.apache.fop.fo.FONode.invalidChildError(FONode.java:534)
	at org.apache.fop.fo.flow.Inline.validateChildNode(Inline.java:123)
	at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:267)
	at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
	at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
	at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
	at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
	at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
	at org.apache.fop.cli.Main.startFOP(Main.java:174)
	at org.apache.fop.cli.Main.main(Main.java:205)

Just great. Now I know exactly what to do. Cry!

Nine tools I can’t live without (for Windows)

First, a relevant disclaimer: I use Windows mostly for two purposes, test my Perl modules under a Windows environment, and printing some stuff as my Mac sometimes can’t find some Windows printers in the network. This said, my Windows runs in a virtual machine, and I install these tools right after installing Windows.

Browser

The first thing you need to know is that Windows does not include a web browser. It includes a tool that is mainly used to download a Web browser. Its name is Internet Explorer, and you can use it to download Firefox, Google Chrome, Safari or Opera. In my main machine, I use Firefox. There are some features that I like that are not available on other browsers. But for my virtual machine I need a tool to check my mail, and to download some other tools. Not much more.

Antivirus

Now I am cheating. In my virtual machine I do not have an antivirus installed. It is too easy to reinstall a new virtual machine, and you all know that an antivirus running is wasting some resources that can be relevant for virtual machines. Nevertheless, I want to suggest two antivirus. In fact, I suggest these two because they are the two I install when I need one (note that I do not install both, I install one or other). I am not sure what is the best. Avira seems to be lighter, AVG seems to be more professional and heavy.

Both these antivirus software have their professional paid version. This means that if you like their performance, you can buy the paid version for better protection. They also include some functionality that are common on current antivirus software, like trojan detection and web site security.

 

Connectivity

I need to transfer files to and from my Mac and/or Linux servers to the Windows machine. For that I can make the file available to download, or I can use a tool to copy files. As FTP is not that secure, the best approach is to use SCP or Secure Copy. For that, I suggest WinSCP tool. It also support FTP, but its main strength is the ability to use the SSH protocol.

A similar necessity raises when I need to connect to a Linux server from Windows. Again, I do not need this when using a virtual machine, as I can use a terminal from the host machine to ssh anywhere I want. But if you have a dual boot machine, or you just work on windows, then you will need this. Putty is the better telnet/ssh client I ever seen for Windows. It not only supports ssh, but it also supports ssh keys, making your connection even more secure.

Version Control

My main repository of code is still a SubVersion one. I am now using GitHub a lot, too, but my main tools are still in the old SVN repository. To checkout and commit from Windows I use TortoiseSVN. Not only because it has a nice and cute logo, but because it integrates perfectly in Explorer. Also, I love a recent feature, where TortoiseSVN commit message window auto-completes your commit messages with the filenames or contents of the modified files. Very cool.

Text Editor

I do not use that much Windows to have a dedicated IDE. I usually use Notepad++ for my editing needs. It knows about file encoding, it knows about end-of-line differences among operating systems, it knows how to highlight main programming languages, it is light and easy to use. It is not full of features, but I do not need them. Or at least, I think I don’t. Also, I confess I never dig much all of its potentialities.

Programming Language

My main programming language is Perl. I occasionally need some C, and some of my Perl modules link to C and C++. So, to fill my need for these three programming languages I choose to install Strawberry Perl. I never ever used Perl with so ease in Windows before Strawberry Perl. It supports more than 90% of CPAN modules, and it includes a C and C++ compilers (gcc based) and a make command. What else one needs?

Compression Tool

Windows knows (it its recent incarnations) about what are zip files. But it ignores all about rar, gzip, bzip2 or tar files. Most Perl modules come in tgz format, so I need a tool to extract them. Most people tend to use WinRar or 7zip. I am not sure why, but I prefer IzArc. It is lightweight, supports most compression algorithms, and integrate pretty well with explorer.

PDF Visualizer

If up to now I defended the use of lightweight applications, now I’m going to the other side, and my choice to read PDF documents is Adobe Reader. There are other free and more lightweight applications, like FoxIt Reader, but I had so many trouble with PDFs and PDFs compatibility that I prefer to have the application from the PDF creators. I know that doesn’t mean much, but at least it can work as an excuse.

What I miss…

There are some tools that I miss. First, I miss a decent command prompt window. One that let me select text, copy and paste easily, that let me make full screen, that let me change easily the font, and not just some stupid predefined sizes. Together with this, a decent command prompt, or shell, with better completion, better prompt configuration, better history, etc. To install cygwin is not an option. For that, I would use linux.

Also, and as I stated above, now I am using GitHub a lot. Then, I miss a Git client. I tried TortoiseGit but it didn’t work well for me. Probably it was a beta release, and now it is better. I need to test. I used the Git binary, that includes a Git shell, and mostly works. But it do not integrate well with the operating system.

Artificial Intelligence for Games errata

This year I am teaching Artificial Intelligence for Games. I grabbed some book PDFs from the Internet (yes, sorry, it would be impossible to buy all the books to choose one, and libraries around doesn’t have books in this thematic) and I chose a pair of books to buy. One of them is this Artificial Intelligence for Games, by Ian Millington and John Funge.

The book is quite complete, the language very accessible, full of code, lots of insights about that developing AI for games means. I really like the book, and I will continue to use in future years if they let me continue teaching this course.

Unfortunately the book is full of small typos and problems. There is an official errata available but it is very incomplete. I started writing my own errata (I’m not repeating the items in the official errata, just adding new errors I find) with some fixes, and some insights on some interpretation problems. I warned Ian Millington about my errata, and he will, hopefully, go through my errata items and decide if they should be included in the official errata. While Ian doesn’t have the time for that, I am sharing my own errata page. Note that I am not professional on this area and I might have misunderstood something…

@GitHub Inconsistency

 

Github Inconsistency

Github Inconsistency

This is something I couldn’t still understand. Not sure if this is a bug or if I am missing some information. This project claims to have 22 open issues, but when I get into the issues page, it shows 24 issues (and the list really includes 24 items). I would say the number in the toolbar is wrong, but probably I am missing some special type of issue that does not get counted?

Being a Dancer

(re-post from blogs.perl.org)

For some time now, I am a Dancer contributor. It all started in the last Christmas (everything in the Perl community start or end at Christmas time), with Dancer Advent Calendar.

Getting a little behind… I tried to learn to use Catalyst some time ago, reading a Packt Publishing book and found at that time that the book was already outdated. Unfortunately that is standard in Technology, and the books that keep up to date for some time are the ones that focus the foundations of computer science, and not the technology itself. It didn’t work. Probably I was not tuned to the MVC model, or I didn’t have a concrete project where to test Catalyst.

Time passed, and I needed to put a website up. CGI was not an option. I do not think CGI is that bad, but if web frameworks exist, is because they lessen the work needed to make a website run. At that time I was pointing to Mojolicious, as I listened to a talk on a Portuguese Perl Workshop, and it seemed easier to learn than Catalyst. When I finally decided to learn a web framework I found that Dancer Advent Calendar, read the first two or three days (can’t remember exactly) and I liked it.

I started to build a web site with it, and it felt good. With little effort I got the basics working. Of course problems arise, and I needed to visit #dancer on irc.perl.org for help. The users present on that channel at the time tried to help me. I confess they didn’t find the solution, as it was some weird problem on redirects and the fact that I needed to use Open3. That was the time when I needed to develop POSIX::Open3.

But since them, I was hanging on #dancer. Listening to development discussion and newbies asking for help. I tried to help them as good as I could. Sometimes I needed to hack Dancer code to correct some bug or add a functionality requested by one of those newbies. And no, I wasn’t a Dancer developer then. Just trying to help.

Accordingly with the Changelog, my first patches were released in Dancer 1.3001. I do not want to search on GitHub the exact date for my first pull request, but this release was out in January/February 2011. That is, only one or two months after I started using Dancer.

The pull requests continue to pop in github. And I can be a hassle, poking the developers to merge my code 🙂 About eleven releases after (a quick count, didn’t take care of what were stable or developer releases), Dancer developers started to name stable releases with names of somebody that helped/contributed a lot to that release. The first release of this kind was named after Michael Schwern, and the next was released after my name (1.3030, April 13th). About four months after I started using Dancer.

As I did not stop to write code, fixing bugs and adding some new features, they made me a Dancer core developer in May 9th.

I continue to help (I think) in the development of Dancer. And it all started with a simple site I needed to put online.

As a final note, my thanks to Alexis Sukrieh, Damien Krotkine, David Precious, Franck Cuny and Sawyer X for putting up with me and for welcoming me to this community.

Packt Publishing needs to learn typography

Packt Publishing

I own some books from Packt Publishing and they are not bad. Of course, each book is different from each other, and some are better than the others. But that is normal that a publishing company that is trying to gain space in the market with serious competitors (like O’Reilly, Apress or Manning) needs to publish a lot, making it more difficult to publish good quality books.

But after having a few of them, my main complain is not regarding the book contents, but the book design. It seems that Packt responsible people does not know typography nor marketing.

Regarding marketing: try to make your books similar. Not only the cover, that you are already doing, but the inside too. They are not very different, but they are different enough to be a pain to read some of them, while other are pleasant to read.

Regarding typography: accordingly with the table of contents of the books I am able to understand there is a chapter level and, inside each chapter, a section and subsection level. But unfortunately, when reading the book, the titles for sections and subsections are similar. If they have some difference, it should be one millimeter or so. That makes reading the book very difficult. The reader never knows if the subject is continuing or changing. You do not need to add numbers to the section and subsection titles, if you do not like them. But change the style! Make one of the titles underlined, or italic, or gray, or something!

Oh, and finally, try to convince authors to make a good index. If your book is in a programming language, or a library, and examples use a specific keyword or function, please add it to the index, and point to the page where it is explained. That’s how users want to consult the index, not looking for the name of the example application.

Book Review: Modern Perl

I bought the Modern Perl book by chromatic. The title is inspiring. There is a lot of people writing Perl code as they were writing years ago. Although Perl still support those syntax and lack of strictness, there is a new trend on Perl code, and actual and future Perl developers should start learning it.

The index of the book is inspiring as well. For one, it starts the chapter on object orientation with Moose and not with the old and crappy Perl OO system (in fact, I started learning Moose, and think there are too much Moose modules, too much documentation, too much of everything, that makes it impossible to find anything you would like). It could talk about Mouse or Moo, it does not matter, as only the basics are explained, and as far as I know, these three frameworks share the basic syntax and behavior.

Also, the book as a good aspect when you look to it in graphical terms. It is quite easy to notice it is typeset with LaTeX and that is nice. And it is typeset with LaTeX using a set of Perl tools to convert from the POD (Perl documentation format) to LaTeX. Unfortunately the bibliographic entry on the book writes LaTeX in ASCII form, but it should render the correct logo for it (there is a command for that, you know?).

The typesetting engine also changed the defaults from LaTeX. And, sorry for the language, they did shit. It is impossible to read a book where you cannot differentiate easily whats a chapter title, a section title or a subsection title. I almost feel tempted to measure the title lines and check how may millimeters there are of difference. More, the examples (and the full book, in fact) have the letters quite small, making it difficult to read.

Enough for the format, now for the contents. After reading the old Learning Book and Programming Book written by Larry, Schwartz and Christiansen, the new versions with Tom Phoenix, and most recent books with brian d foy, I should say chromatic is in the bottom regarding read easiness and sense of humor. Yes, older books had much more sense of humor than current ones.

The book is not for beginners. There are examples that are not complete. They have some text placed along with the example to explain it, but sometimes the most important piece to the beginning programmer is just missing. As an example, chromatic tries to explain that using $_ inside functions are bad, because you can’t use those functions safely on a for loop. He shows the for loop, shows the call for a function, but doesn’t show the function body. I think newbies will be kind of lost.

This said, I should congratulate chromatic and Onyx Neon for the courage and work publishing this book. Nevertheless, I think it needs some more work (both typographical and content related) and that a second edition is required as soon as possible.

Hiding the bird’s guts

Probably this is a stupid rant/question. If so, please clarify me. I can live without the insults. Really 🙂

OK, on to the relevant stuff. Twitter has a new OAuth authentication mechanism. To write an application able to post on twitter your application need to be registered and have a consumer key. That key is used to identify your application to twitter when requesting permissions to a user to post using her credentials.

Now, the problem is when your application is written in a scripting language, like Perl, Python, Ruby or anything similar. Will you insert this key verbatim in the source code? Then, when shipping your app, others can grab that token and use it as if it were your app. You can encrypt it, but you need to ship the decryption algorithm as well, so, making the key verbatim.

One of two things can be happening: or twitter guys are not good on this API thing, or I am being totally stupid.

DevC++ and their lack of discernment

If you know me, you know that I program mainly C and Perl, that my preferred editor is Emacs, and that I use mostly Mac OS X for that task.

But, I teach programming, and sometimes I teach programming to students that never heard of Linux or, worse, that never used the command line of Windows. Given this, I tend to search for simple solutions to help them do not deal with the command line so I can use more time for the task of learning how to program.

With that in mind, I decided to suggest a C IDE for windows. The main IDE (I think) is Visual Studio. Although it is paid, there are protocols between Microsoft and the universities to use their software for free for academic purposes. But the Visual Studio installation disc is some hundreds of megabytes. That is not very portable. Also, the application is quite heavy when running. I decided to search for an alternative, and found DevC++. It is just 10 megabytes of download, uses GCC (or MinGW), and works quite well.

It just have one big and stupid problem. Although DevC++ is being developed for more than a decade, their developers did not implement, yet, a pause mechanism for when you are running a console program. In their faq they suggest to add a ‘system(“PAUSE”)’ in the end of the code. That is just stupid! Why to have to add such a line in your code, just during development, and then remove it when you want to ship the application? It would be quite more interesting to have an option in the IDE to force that window not to close. Some other similar applications, like the Lazarus IDE for Pascal, include that option already.

Now I need to decide if I should go back to Visual Studio, if I should explain why DevC++ doesn’t work properly, and explain how to add a pause at the end of the application, of if I should go back and teach students how to test their applications right from the command line.

Map-Reduce, or why I hate software patents.

In the recent times you should be hearing a lot on map-reduce. I first heard of the term in last year Codebits. Although I wasn’t there, there was a talk with that title. I confess that knowing that map and reduce are common functional operators on different programming languages, I did not look to the talk abstract. During this year Yet Another Perl Workshop Europe, in Pisa, I saw a book on Hadoop, asked what it was about to a friend that wanted to buy it, and he said: a framework to implement Map-Reduce.
 
That made me think.. wait.. this should be the name of something different from what I though it was. Looking deeper I understood the concept. Googling, I found Google filled the patent request in 2004, and patented it in 2010. Found also that I used that construct in 2007, and documented it on my PhD thesis in 2008. Of course I did not call it Map-Reduce. In fact I did not call it anything fancy. It was just a way to get to results. Named it as my “divide and conquer approach”. And I did not heard of Google approach as well. I just got to it because I needed some results.
 
So, this is yet another reason why I hate software patents.