web developer & system programmer

coder . cl

ramblings and thoughts on programming...


a working AST generator

published: 24-10-2012 / updated: 25-10-2012
posted in: development, haskell, programming, tips
by Daniel Molina Wegener

As you know I am trying to participate on the last challenge on the blog La Sombra de Dijkstra, where you must provide a program that compares two Fortran IV programs and must determine if both programs are equivalent. I have finished the first component, the Abstract Syntax Tree of the program. This will allow me to run the program creating an interpreter, and also will allow me to analyze the program structure — the complete Abstract Syntax Tree as graph — and make some heuristics on it.

compiler flags for correctness

published: 05-10-2012 / updated: 05-10-2012
posted in: c, development, haskell, programming, tips
by Daniel Molina Wegener

As I have discussed on a previous blog post, static typing helps on correctness by providing well-typed programs through type checking algorithms. Compiler warning messages and compiler error messages are not thrown as they were made by a capricious developer. Almost all of them are following a language definition, and they help if you want to build better programs. The more strict are your compiler flags, better are your programs. Using language extensions, which are not present on their standard definitions is not so cool as it seems. That depends on the language, sometimes there is very long time after certain language extensions are passed to the language definition. So, you should try to look on how can you write better code for that language without abusing of its extensions and extra features provided by the compiler.

base conversion tricks

published: 04-10-2012 / updated: 04-10-2012
posted in: c, development, haskell, programming, tips
by Daniel Molina Wegener

Base conversion can be used to compress number representations, and can be used to hide the real number representation. The algorithm is well known, anyone can program that algorithm, and it is not so hard to handle. I was playing with Haskell writing that algorithm to check how effective is that algorithm to create URL shorteners. My idea is quite simple, you have an URL database ID, which is an integer number, indexed as many entries on the database, but once the database starts growing, the number can reach a length that is not so easy to remember. For example the ID 999 999 999 999 is not so easy to remember.

type safety is not security

published: 02-10-2012 / updated: 02-10-2012
posted in: c, development, haskell, programming, rants, tips
by Daniel Molina Wegener

Standar ML is defined as safe using the following definition «ML is safe, in that a program that passes the type-checker cannot dump core, access private fields of abstract data types, mistake integers for pointers, or otherwise “go wrong.”». A type-checker verifies that each term used in the programming language should have the correct type once it is used. For example if a function is defined to receive an integer type, once it is called, an integer term should be used, otherwise the compiler may throw an error and the execution “goes wrong”. If the type-checking algorithm accepts the program, then it is well-typed. When a programming language has a type-checking algorithm on its compiler, we call it statically-typed. Dynamic typing does not have a type checker on its compiler, you can write the same function, it will not have any sentence defining an input type, and it will be able to receive a string when an integer is required.

CSDS is comming…

published: 26-09-2012 / updated: 26-09-2012
posted in: development, haskell, programming, projects
by Daniel Molina Wegener

I have started a new project on Haskell. It is called CSDS, or Core Stateful Data Structures. It will hold common functional data structures, mostly based on the implementation described on the book “Purely Functional Data Structures”, but on Haskell I am using type classes and implementing some common interfaces for that kind of data structures. Is very nice to work on project like this, I think that I will use this kind of project on integrations with projects like Cloud Haskell, for distributed processing. For example some of them like the StackLT and QueueLT are providing a class interface to work with the Foldable and Monoid type classes.

choose C or C++

published: 18-09-2012 / updated: 18-09-2012
posted in: c, c++, development, haskell, programming, tips
by Daniel Molina Wegener

How to choose between C and C++?. The answer is pretty clear. C allows powerful data type abstractions using three star and two star pointers, C++ only allows one star pointers. Also void pointers on C are more powerful once you try to pass abstract parameters to functions and procedures. The abstractions on C++ are built on top of virtual classes and templates, not its data types as C does. So, if you need to create complex data types, for example to handle hardware buffers, you should use C rather than C++, but if you want to create abstractions to manage real life objects, an object oriented interface like C++ does have is pretty good, enough to support almost any object oriented abstraction that you want to implement.

monoids in haskell

published: 06-09-2012 / updated: 06-09-2012
posted in: development, haskell, programming, tips
by Daniel Molina Wegener

A Monoid is a well known abstraction where you have an operation or function, a neutral element and a set that can be operated with that operation or function. Given that description, on Haskell you have an already defined Monoid class which is implemented on common types like Strings. The main monoidal String operation is the concatenation, using the (++) operation, so can have a clear example of the given description in the code that follows.