Guillaume “Zifro” Desrat’s former blog

DSL with Ruby : how to get a step ahead ? (make it written in French, for my colleagues’ sake)

Filed under: work, WinDEV, code, Ruby — Zifro November 29, 2006 @ 12:50 am

DSL is the acronym for Domain Specific Language. A DSL is a language designed for a particular purpose, for an intended audience who may not feel fine with a complex programming language. For example, Microsoft Excel macros are part of a DSL.

I’m currently working on an application which exports data into a text file, formatted with given tags and given parameters, then send it to another remote software, which will handle it (I skip here the whole process, which isn’t interesting at all for those who don’t work on it) to finally have the data printed and sent by mail.

WinDEV doesn’t offer built-in testing, so I made the application write a checksum like log, to verify the number of each type of data exported. Well.
But as we’ve got several undocumented (yeah, I know, real developers don’t write neither documentation nor comments, I should just read the code…) data handling rules, some of the corrections I add last month made errors appear in other parts of the file generated.
At this point, it gets enough freaky for me. I NEED REAL TESTS !

So, I decided to write, on my spare time, a tool to validate the file (if fields are all filled, if the values make sense, if the email field really contains an email address, and so on). Playing with metaprogramming and code injection, I got this skeleton of testing code (hiding all the automagical thingies in FileAnalysis.rb) :

#!/usr/local/bin/ruby -w

require "FileAnalysis"
include FileAnalysis

trap('SIGINT') { puts "\n\nAborting tests...\nBe sure to run *ALL* the tests at once from time to time ;-) \n\n"
exit
}

FileForPrinting.is "MMMMMMMM_data_2006_11.txt"
FileForPrinting.analyze do |line|

line.store? do |mag|

store.should_have_all_fields_filled
store.should_have_a_valid_email_address

end

line.cust? do |cust|
# here goes the tests for customers lines
end

line.art? do |art|
# here go the tests for article lines
end

end

This looks like a DSL to me (and it’s pretty like “Creating DSLs with Ruby” on Artima.com). Tests are quick to write, and fully understandable (okay, for those who know which tags are in the file, and which tests could apply to those lines).

Unfortunatly, my colleagues, who’ll have to deal with this piece of code, sooner or later, aren’t… English-friendly :)
For one thing, we don’t write code in English at work (WinDEV is set to “I code in French, pal” mode), and they’re not used to read and write this language. On the other hand, I don’t feel comfortable with writing tests in English for something I work on daily, in French. I mean : why the hell would I write line.store? instead of ligne.magasin ?

So I’ve the idea of pusching the DSL work one step further, turning it into a French written test tool, which would look like :

FichierAImprimer.est "MMMMMMMM_data_2006_11.txt"
FichierAImprimer.analyse ligne par ligne

ligne de type magasin ?

la ligne devrait avoir tous les champs remplis
le magasin devrait avoir une adresse electronique valide

ligne de type virement ?

...

fin des tests

Okay, that would be very cool. Of course, I might end up writing slightly different code lines, to save some time working on that, but I think you get the idea. I suppose I’ll call a method, just after starting the program, as the first line of the code, to parse the file (or, maybe another one which will contain the tests) to replace some strings by another, according to rules I’ll set up (delete a blank space if it is immediately followed by a “?”, “le” and “la” at beginning of the line should be deleted as well, and so on…).

This would mix the two categories of DSL : the ones which are new dedicated languages to serve one goal, and the ones which are evolution of existing programming languages.

At this point, I have only two questions to you, readers : have you ever written a DSL to be used by non-English people, and what’s your opinion about all this ?

Yet Another WinDEV/HyperFile Bug : Network disconnections

Filed under: WinDEV — Zifro November 24, 2006 @ 3:45 am

I promised to write a long post about what I feel about WinDEV in details, but I don’t manage enough time to write something clean and clear, summing up why you shouldn’t and why you might want to use it.

By the time I prepare it, let’s take a look at this : when using HyperFile in classic mode, if the box hosting your WinDEV program get disconnected from the network for one reason or another, you must expect the HyperFile mechanism to yell at you because it can’t find your remote databse any more. And that even if the disconnection is so short MS Exchange doesn’t notice it and/or you don’t loose the network drives attachment.

See by yourself.

Really. Cutting-edge technology.

Tuesday, WinDEV.

Filed under: work, WinDEV, code — Zifro September 12, 2006 @ 1:46 pm

As I was to find out a solution to the big number problem in our software, I imagined I could write the code in Ruby, make it stand-alone with rubyscript2exe, and call it from WinDEV.

*Laughs*

The Ruby part went fine (of course), but I couldn’t manage to get something else than 0 when I call it from WinDEV. And then I noticed that I forgot a blank space, so instead of calling “C:\zlab\rlmc.exe 8708″, it was launching “C:\zlab\rlmc.exe8708″, FUCKING SILENTLY !

So after some tests, I went to this conclusion : one of the two signatures of the LanceAppli function doesn’t work (by work I mean raise and exception in such a case).

If you’re interested in knowning more about it, here you are :

My advice : DON’T MESS WITH WINDEV OR YOU’LL GO INSANE !

(and finally, I coded an int z_modulo(string s, int n) function to keep all the code in WinDEV)

Monday, WinDEV.

Filed under: work, WinDEV, code, Ruby — Zifro September 11, 2006 @ 5:59 pm

I’m currently working on software to help our customers save time, by extracting data from their databases, to generate a big file and then send it to a partner, who’ll print all the letters and checks.

Honestly that’s a big advance for our customers, something like one day work saved.
But as my company will handle some of the administrative part, I have to write the checks parameters, like the name, the address and stuff.

One of these parameters is the (sort of) checksum of the magnetic ligne at the bottom of the check ; it aims at checking the check authenticity.
The algorithm I was given by our bank director office is the following :

rlmc = 97 - (N x 100 - 97) where N is the concatenation of the 31 digits of the magnetic line (check number and two bank codes).

So I code it, run it, and WinDEV : string to number convertion and big numbers handling TADA !
It appears that WinDEV doesn’t handle big numbers (string to number convertion sucks hard too).

So, “just to try”, I typed in the same thing in irb :
irb(main):001:0> s = "6459010034010041908006791980430"
=> "6459010034010041908006791980430"
irb(main):002:0> rlmc = 97 - ((s.to_i * 100).modulo(97))
=> 54
irb(main):003:0>

Oh… it works :p

New project, new horrific code lines

Filed under: work, WinDEV, code — Zifro August 7, 2006 @ 12:00 pm

I’m now working on a new project. Well, it’s something new for me, but the software I’m diving into has been used for years to retrieve data from our shops each night.

The code is pure shit.

For example, there is a procedure that compare two dates, contained in two global variables, and returns the result in the variable passed as parameter. See :

procedure compare_dates (result)

// comparison code…

result = …

Better seeing that than being blind, hu ?

I’m still alive

Filed under: work, WinDEV — Zifro June 1, 2006 @ 9:48 am

I’m still alive.

I’m still wondering why I’m going to work, daily. Oh, to have money… I had forgotten that.

Well, WinDEV still depresses me, but I’m thinking of workin on my own on various projects (related to the domain names I bought : bsdlab.eu, bsdgroups.eu, bsdcommunity.eu).

Spread the word : WinDEV sucks.

WinDEV sucks (again)

Filed under: work, WinDEV, code — Zifro May 22, 2006 @ 1:00 pm

Yes, it sucks. I played a bit with its Object-Oriented features… damn ! You can’t test the class the objects belong to (typevar returns wlInstance and nothing more) , you can’t create objects and send them to a method (you must tie them to a var)…

You don’t use ::Creator, but var = gimme a (yes !).

Sorry, PC Soft guys, this is not what I call OOP.
Well, maybe it’ll be fixed in WinDEV 30, but it depresses me a lot to work with that.

WinDEV sucks (and I’ll proof that)

Filed under: WinDEV, code — Zifro May 18, 2006 @ 9:21 am

At work I use an IDE called WinDEV, that aims at making development painless. But it sucks. Really.  The language has no pointers, no lists, no dynamic arrays, hash-like structures only return string elements, and, more icing on the cake, some of the built-in functions and procedures make the developper (me) go mad.

Imagine : I wanted to list the files contained in a directory, and then attach them to an email. Quite simple hu ?
No :-)

The function fListeFichiers returns the number of files in a directory. It takes three parameters : the files mask (like “C:\MyApp\SubDirectory\*.pdf”), a string containing the name of the procedure which will be called for each file found (and which has a particular signature, something like “path, filename, pointer”), and, a pointer that will be given to the procedure mentionned above.

Doesn’t that sound nice ? Even if WinDEV help doesn’t know what a pointer is… I wish I could use Ruby (my current favourite language) to write something clear like :

Dir::chdir(the_dir)
foreach Dir[*\.pdf] { |f| email.attach(f) }

*sigh* WinDEV makes me love Ruby, Perl, and all those real languages. I think I gonna like C more from now.

Ruby & Hyperfile (WinDEV database files)

Filed under: WinDEV, code, Ruby — Zifro May 17, 2006 @ 1:54 pm

Anyone who would know how to CRUD (Create, Read, Update, Delete) WinDEV Hyperfiles from Ruby is welcome to teach me.

* Zifro sits and waits