Back to F#

It’s been a while since I’ve been doing functional programming.

What I remember it was really fun, and I did much less debugging than I am doing right now, using C++. Am I the only one surprised about it?

While I do think that C++ skills are important and I do not intend to stop learning it, from now on I will try to write F# and Ocaml (sometimes Pyhton by side).  I get much more productive this way, and I can in turn write something fun more quickly…

As a first step, I’ve decided to finish doing the exercises in Functional programming using F# and do the algorithm and data structures assignments in Data Structures & Algorithm Analysis in C++ also in F# and see how it goes.

More updates soon…

Brushing up my algorithm skills

It has been a while since I’ve written a post in this blog.

I feel pretty confident with my C++ coding skills for now. I am still green, however I am able to express my ideas in code when I need to. It is time to take my skills to next level and in order to do that I have decided to refresh my algorithmic skills.

While I am not too bad in theory (I am pursuing Ph.D in combinatorics after all) I do not have much experience coding algorithms and in order to get more skilled in that I am going through Data Structures & Algorithm Analysis in C++. While reviews for the book are mixed, it has the advantage of using modern C++, which is the language I am focusing on right now.

I will soon begin to write things I learn along the way.

Here is the link to GitHub repository. It is empty now, things will change rally soon.

I hope I will have something interesting to write about soon enough.

Have a nice day!


How to learn from your errors

Everyone makes mistakes. Especially when programming. Especially when you learn. Actually when learning to program, it is important to make mistakes, try to break the program and see what happens. Do it. It will make you understand what is going under the hood much better.

One of the best advice I can give to other beginner programmers – learn to use the debugger as quickly as possible. Don’t be afraid to make mistakes. Actually make them on purpose. And examine what the debugger is telling you. It will make you understand the computer much better.


Defining input and output operators cheatsheet.

When defining a new type in C++, one of the things that need to be taken care of is how to read and write them. Suppose that we have defined a new type.

struct My_new_type {

Now you want to be able to read and write your new type.

How is it done? One of the approaches (applicable to many other languages) is to define functions that do just that.

void read_my_new_type(istream& is, My_new_type& my_object);
void display_my_new_type(ostream& os, My_new_type my_object);

or one can use overloaded operators, to make the input and output more uniform.

ostream& operator << (ostream& os, My_new_type my_object);

for output and

istream& operator >> (stream& is, My_new_type& my_object);

for input.

The second way is more concise when used in code because you can just write

cout << my_object;

instead of

display_my_new_type(cout, person);

On the other hand the second form has the advantage of arguably being more clear sometimes. What the function does is clearly displayed in its name while the fact that << means output operator is not always clear, since << can mean bit wise shift as well.

However there are few things to keep in mind when writing a user input function or operator.

Input function or operator has the following form. It is important to handle the input errors, otherwise things get broken easily and quickly…

my_input_function(istream& is, My_new_type& my_object) {
    initialize the values to read;
    read the values;
    if(read wasn't successful) return is;
    if(wrong format) {
        set the stream to fail (usually done by is.clear(ios_base::fail_bit) );
        return is;
    set the new value of my_object;

Output is usually easier, because error handling usually done by the output stream itself.

my_output_function(istream& is, My_new_type my_object) {
    os << object data in desired format;

Things can change but that's the general form.
That's what I do when defining input and output operators for new type first tine to get things working quickly.

I would like to hear your comments and know if you have found any errors.

Happy coding.

First post

Hey there.

I have been really bored lately. Work, family, bills… While all of those are good and important things, routine is making me feel old and stupid. I have decided to pursue my childhood dreams… I always wanted to make games… and robots. And I am going to give it a try. And I am serious about it this time (really-really!!!).

I am writing this blog to track my progress and document the things I have learnt along the way.

I hope it will get filled with interesting things soon (which means that I am making a quick progress).

That’s it for now.