How note to keep yourself from getting rusty…

Contrary to the title this post is not about Rust language or how to stay away from it. (I am focusing on C++, Python and F# right now). It is about what to do when you have no ideas what to code.

First of all, you you don’t have no idea what to code, some people might say that it is a sign that programming is not for you. And they might be right you know. It is probably not for me, that’s why I am a mathematician (sorta).

However, what happens if you are (like me) stubborn or dumb and not willing to accept that simple fact? What should you do after you learnt to write a code in some language and not know what to do yet? Well, I have an advice.

First, you can just try to get a job – there is high demand from programmers, and even if you don’t have a descent skill (or any skill at all) today, unlike 10 or 20 years ago you still can pass the interview and get the job. Weird, but it seems this way for some reason.

Other route is – sign up SPOJ or any other competitive programming site and start solving problems, as much as you can. There are many problems for various skill levels… And even you completely lack any skill like me, you can still solve a few and start making progress.

Well, who are you waiting for?

Sign up and start solving problems.

Have fun!

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 {
    Contents;
}

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.

Cheers.
Happy coding.

Why I am writing this blog?

Welcome to my blog.

In this post I will tell why I have decided to begin writing this blog and what are its purposes.

I have been programming since I have been a teenager, learnt C when I was at 7th or 8th grade. However, programming has never been my main focus. In high school I wanted to be a veterinarian, hence I’ve focused most of the time on biology and chemistry.

After my army service, I’ve thought about becoming an electronics engineer, however I fell in love with mathematics during my freshman year and went that route, until I’ve found myself in middle of a PhD. While I do like mathematics, I’ve felt “stuck”  and bored lately. In an attempt to get a breath of fresh air I’ve decided to learn to program more seriously.

You can argue that it is a weird way to fight boredom, however I always found programming fun as activity itself. I like solving problem, and most programming at its core is solving problems. Besides that, programming is creative activity similar to painting, writing or creating music. Code can be a form of self expression. And at last, but not least, programming allows to express your ideas and give them a tangible form, and gives you a sort of “super-powers” allowing yourself to create new things.

So what am I going to write about, for now? While I have a bit of experience writing code, I have to admit that I’ve never done it seriously for an extended period of time, hence I can still be considered a “beginner”. So I expect to learn a lot of new things along the way. The ones I find useful or interesting, I will try to write here.

Saying “learn to program more seriously” is a bit abstract. So what do I plan to do for now? It is not a secret that in order to become better at programming one needs to do more programming.

What sort of programming do I plan to do? Well, since this is “programming for fun” blog, things I do are supposed to be fun, right? What fun things one can do with a computer? That’s right  – play games! But what is more fun than playing games? Making games others can play. Besides being “fun” games are pretty complicated pieces of software, and making them will allow me to write a lot of non-trivial code and touch various areas of computer science.

Another thing that I find fun is solving puzzles. Hence, I will try to solve algorithmic problems from time to time as well. Last thing I have been interested in lately is machine learning and AI which I find very exciting. I plan to learn the topic a bit in close future as well.

I hope I will have more concrete and more interesting things to write about soon.

Until next time!