Blogs

Another complex Shisen-Sho game!

In most cases, Shisen-Sho games have tiles that can be removed at the very top. That's how you start playing, by removing the top tiles first and moving downward from there. Most often, the best move is to collect the two closest tiles together and you win first time you play a game.

This one is different. That is, you still remove tiles that are together, but you have to work in the middle and the bottom a lot before you can start working on the top. This makes the game much harder to complete.

I made a picture of the game. This is from my 4K monitor, so very high quality. Click on the ...

Not Registered On Network (Samsung Galaxy J7—Android)

Today I tried to make a call from my cell phone to my landline. It did not work. Instead, I got, pretty quickly, this error:

Not Registered On Network

I'm using T-Mobile and my 3 other family members did not complain about their functionality so I would imagine that our accounts are just fine.

Looking for the error, I found one person who said he had the problem too and by restarting the phone it would fix his problem... for some 30 seconds.

Well... I thought I would give it a try and sure enough once I had my phone restarted I received the 5 or 6 text messages I was expecting and ...

Go tests are run concurrently!

Go tests are run concurrently in their own context

I ran in a problem while writing go tests... and it looked like some parallelism or at least concurrency issues.

The initialization would run twice and not finish properly the second time. That means it would load a file from a test, a file which is rather bad (read invalid) outside of that one test.

So I looked around to see what was happening and that's how I learned that tests in go run concurrently. It sounds all good unless you want to do integration testing because such require a state which is actually not reachable if your unit tests run concurrently. But why is that?

Well... ...

Common bug in Go, maybe they did not resolve anything?

Variable shadowing, a common problem, no good solution in modern languages to avoid it.

C++ is not that bad!

With C++, and derivative, you can shadow any one variable over and over again:

int var;

void myfunc()
{
    int var;

    if(expr)
    {
        int var;

        ...
    }
}

In this example, I shadow the var variable twice within myfunc().

In itself, it doesn't hurt, but it is very often that when you do that, you did not mean to. That is, it's not unlikely that you reuse var within the function thinking it's the global variable or the first instance in myfunc() from the outermost block of the function.

I have two rules I follow in C++ ...

The new C++17 [[fallthrough]] "attribute"

Here I wanted to talk briefly about this new C++17 attribute:

[[fallthrough]];

I wanted that attribute like 30 years ago but the compiler programmers were definitely not ready to allow us to have safe coding practices...

Back then, any potential error was a beautiful feature. I'm really glad that some people pushed the idea that having tons of warnings about very possibly invalid code is a good thing long term. I am fixing some of my bugs just by compiling my code with newer versions of the compiler!

Now... I ran in a few problems with that new attribute. The fact is that it's a ...

A little bit of Go!

I changed a goroutine to make use a service which gets awaken whenever a signal happens. This is used because the signal is sent only in very complicated cases and I wanted to remove the tests from the bottom goroutine (many of the parameters are from other structures not available here.)

Here I wanted to get the basics to show how it's done.

var (
  someMutex      sync.Mutex
  someCond       *sync.Cond
  someState      bool
)

func init() {
  someCond = sync.NewCond(&someMutex)
  go someLoop()
}

func sendSignal() {
  someMutex.Lock()
  defer someMutex.Unlock()

  ...

C++: Why should I breakup my expressions?

One Line Expressions

There has been and I'm sure there still are many talks about whether to write it all on one line or break up expressions on many lines.

One Line Pros

The only pro I can think of for having everything on the same line is conciseness. For example:

*dst++ = *src++;

This is a very clear statement for most every C/C++ programmer.

I have to agree with this fact and I at times use such lines of code too...

One Line Cons

Now, I write very large libraries and programs (thousands when not ten of thousands or even hundreds of thousand lines of code....) and it ...

Meta-programming, promoting a type without changing the sign

Today I found that one of my functions would overflow. Here is a simplified version of it:

template<typename T>
T scale(T value, T position, T count)
{
    return (value * position) / count;
}

As we can see, all variables are of type T. So if the multiplication overflows, the function returns an invalid result. To fix this, I wanted to promote all the variables to the latest possible integer (keeping the sign) or double (in my case the support for floating points was just for the type float so no need for long double.)

As a result I wrote a structure using meta-programming as ...

Creating a Gantt Chart for your Project for Free

ProjectLibre Screenshot

Today I wanted to work on the schedule of a project with the proper dependencies. More or less, I had the project tasks laid out as a long list (As I would if I were the only one to work on said project) and I needed to answer two main questions:

  • How much will it cost?
  • How many resources do we need?

The other question, which is always really hard to answer as a software developer, was: Can you make it happen in 6 months? But you know the answer to that one: Of Course! (and 6 months later: Not!)

So, I remembedered seeing a manager using MS Project which is what it is. In ...

ASCII Art Pony

Isn't that cool?

I just find it really facinating that some people have an eye to draw anything with anything (in this case, a little pony with wings using just ASCII characters.)

Have you ever tried to come up with a drawing of your own that would look as good as this one?

      ,;;*;;;;,
     .-'``;-');;.
    /'  .-.  /*;;
  .'    \d    \;;               .;;;,
 / o      `    \;    ,__.     ,;*;;;*;,
 \__, _.__,'   \_.-') __)--.;;;;;*;;;;,
  `""`;;;\       /-')_) __)  `\' ';;;;;;
     ;*;;;        -') `)_)  |\ |  ;;;;*;
     ...