Code and Bugs

Coding things

Category: Ideas

Mazes (1)

As mentioned previously, I had an assignment which involved constructing a maze from code and letting a robot escape from it. This series won’t follow the second part, it will concentrate on maze specific topics. I will write about maze generation, maze drawing, maze counting and several other aspects. Maybe I’ll touch several properties of the mazes, possibly I’ll write about something like the moments in statistics. Will see where this series will end and what areas will be covered by it.

Read the rest of this entry »

Java Type Signatures

This year, I had to do several assignments in Java. Some of them didn’t require me to use a specific IDE but there was one arguing that we should use Eclipse because it helps us in development better than any other tool.

Read the rest of this entry »

HaCoTeB is dead

A while ago I started a project which promised to make posting code snippets on wordpress.com blogs easy as pie. However, things didn’t worked well in the end.

Read the rest of this entry »

Programmer’s context switch

Say you are working on one project when someone calls you or sends you a mail asking you to look into another project, either a bug in one of your old projects or problem in his. Although programmers don’t like interruptions, this is a case where you have to do that context switch and return to your project afterwards. So, how to do this efficiently?

Read the rest of this entry »

Enter HaCoTeB

I am dissatisfied with the WordPress.com code posting capabilities. All of the possible solutions (using the included <code> tag or the included [ code ] plug-in or posting the entire html generated from the code via vim’s TOhtml or via highlight) were incomplete.

Read the rest of this entry »

Craft or art?

One of my teachers once said to some of his students: «Your job is both beautiful and cursed». He was referring to the fact that, in Computer Science, one has to always learn something new while being certain that what he learns will become obsolete in a shorter or longer period of time.

However, this is only a partial reason. At least, for the programming part of Computer Science.

Read the rest of this entry »

Visual Haskell Debugger (part 2)

The idea from the previous article received a lot of feedback both in the form of comments to the article or on reddit or on Haskell-Cafe (though, not on a dedicated topic).

For another proof of the idea, I will draw some diagrams by hand for the following suggested pieces of code. As you will see in this article, the drawing will evolve as I will tackle with more complex examples (and there are still pieces of code that I cannot render right now).

Read the rest of this entry »

Haskell Project Idea

Since a few days ago a little idea is bugging me: what if debugging Haskell programs would be reduced to a graphical interface and some clicks here and there to spot the problem?

What I have in mind is a new debugger very much GUI oriented. It will parse the code and interpret it and then it will offer a picture to the user in the GUI program.

For now, I will consider only the case of functions with no side effects. Suppose our user has, at some moment in the debugging phase, observed that one particular function gives wrong results. The only method of debugging that I know as of now is to use Debug.Trace and the trace function. However, this method involves changes to the code, none of which will really solve the bug. Cannot we do better?

I think that we can. Suppose that the code debugged is the following (simple demonstrative example) and that the user is debugging f.

f :: Int -> Int -> Int
f x y  = y + g x
 
g :: Int -> Int
g = (-1)

and the user observes that it gives output 7 instead of 8 when applied to 3 and 5. How the users reaches these values is beyond the scope of this article. He might have used quickcheck or he might have manually tested the code, it doesn’t matter. What does matter is what the proposed tool will show to the user:

Yes, a simple image describing only the inputs and the outputs of the function. What cannot be seen from the figure is that, although what he sees is a very abstract representation of his function, by clicking on the f name the tool will display the internals of the function, for the case taken.

The meaning of the rounded decorator around the + function is that that function’s implementation was not written by the user and it shouldn’t be debugged. However, the g function can be debugged and, by clicking on it, the GUI will open a new image, as if the user was really debugging function g right now.

Because this function doesn’t involve other user defined functions, the GUI will redirect any click on the function name to the actual implementation. The user would then be able to see what went wrong and correct the function (g was supposed to be id).

This was a simple example and the bug could be seen with naked eyes. However, this is not always the case and I think that this tool can help in debugging.

To be more helpful, I intend to extend this tool such that it can run a quickcheck test suite over one function using the informations that the user provide via the GUI. I intend to make the program to be capable of displaying informations at the type level and, maybe, allow the user to drag the boxes representing the functions and try to match them like some jigsaw puzzle. If there would be a missing link, the project might search on hoogle or hayoo for any function that matches that signature and offer a suggestion to the user.

I still have to think what should be done for functions returning other functions. I will not give up on handling curried functions but I haven’t decided yet how this would be represented graphically

Finally, maybe this tool can be also integrated with hlint, providing a visual feedback on common warnings issued by this tool (for example, runing hlint over one piece of my code showed 4 similar warnings concerning it)

Now, I don’t usually speak about my ideas in front of the public (or even remotely like blogging about it). I did this right now because this would be my first Haskell based project which could affect the community if all things are going well. But, before starting it, I want to see some feedback of whether this is needed, whether this is doable in one summer and whether this hasn’t been done before (I did a short search but found only tools remotely related to this project – either not debugging or not graphically displaying the code).

Thus, I finish this article by inviting every reader to give a feedback related to this project in the next few days. Depending on your feedback I may start working on a useful project or realise that my idea is not really such a brilliant one.

Follow

Get every new post delivered to your Inbox.