Learning C++, day three: Integer overflow

I was happily playing with my shiny new prime-number-checker, trying out how loops work in C++. When I started entering stupidly big numbers, something strange happened. ./main Enter a number: 5784320578432578493207508493 Congratulations, it's prime! Except, that is not actually a prime number. I can’t have typed a prime number by randomly banging on the keypad. What’s going on? I didn’t code any input sanitization in my prime-number-checker, so let’s check what my program actually gets. I am now removing all the boring logic, and compiling this simple code: ...

May 7, 2019 · Pierre Prinetti

Learning C++, day two

My first steps: I have enrolled for a Pluralsight course I have installed a C++ syntax extension on my beloved editor. Discovery #1: Classes feel like language extensions In Go, primitive types are special. Some properties only apply to them; for example, there is no way of defining a behaviour for make(myType). Every primitive type brings its own built-in constructor, and custom types inherit the constructor from the primitive type they’re based on. If you want a new instance of your type to be any different than “the zero value for the underlying type”, then you have to declare a very explicit New function and write a compelling comment advocating its use. ...

May 5, 2019 · Pierre Prinetti

Learning C++, day one

A long time ago, I started programming with Python. Everything was great and I was happy. Then I discovered Go. Everything was fast and portable and powerful. This is my first day into learning C++. Why? A SQL metaphor I used to be contributor to an opensource Go database adaptor: something like an object-relational mapper. Back then, I was fascinated by the idea of abstracting away SQL from my applications. ...

May 4, 2019 · Pierre Prinetti