There are no goals to be reached if there’s no discipline

smallsteps

Goals are meant to be completed, but without discipline a person can easily lose sight of what he or she wants. Losing sight is quite easy, from wanting to build an empire to sitting on the couch watching TV series. I can’t say I blame you if you want to enjoy Breaking Bad, Game of Thrones, and many other awesome series. Take in moderation though.

I haven’t been this focused for a long time. I would say that it feels good to have a clear vision of where I want to initially start, to where I want to be at the end of the journey. Those who know me knows how much I’ve struggled, others can just assume. And yet I move forward, because we really need to move forward regardless of what people think of you or me. Cut them off and carry on as you don’t need them, I would say. I find that surrounding myself with positive individuals can actually be incredibly refreshing than the usual sassy crap you get on the internet. Even if you had the greatest bullshit filter at some point you will inevitable fall for bullshit.

Which is quite amusing, because you don’t know you are being treated like crap until someone starts treating you like a human being, and respect you for what you are. Then you know the difference; it’s why I say “cut them off, you don’t need them”.

As for the picture I’m happy to say that I’ve reached a new milestone on the application I’ve been building. I’ll be re-branding it pretty soon. I’m quite happy with the results I’ve been getting from Qt Quick and I feel like I’ve made the right decision to stick with it.

I’m still amazed at how fast and lean(may not be so lean to others) C++ can be under a language with no garbage collector showed me how amazing and painful it can be. Iterating through a numerical array from 1 to 100,000 in less than a second really makes you think, and yes I know, it’s pretty impractical to use that as a measure of speed.

I’ve more or less taken a liking to C++ and I hope to start a career out of it. I may not be the best, but I sure as hell am pretty fast on taking initiative on things that I don’t know.

Although, remember that learning is not linear. You can pour 2-3 hours a day and do all the activities you want. Grinding 12 hours a day is just a recipe to burnt out quickly.

With that said, I have revitalized my interest in programming and creating user-focused applications whether it’s making a intuitive user interface or bringing a competitive product to the table I’ve never felt so prepared, yet I can’t give in to this feeling as you all know programming is pretty big, incredibly big so I can’t just put my glove off and pretend I’m done learning.

Simplifying the design

Recently I got all excited on my progress with C++. Sometimes when there’s a blocker in your way and you can’t tackle it with your current knowledge then it’s time to sit, and think of a different strategy. In my case it was a case of selfishness and petty design that led me to this convoluted design in the application I’ve been working on.

I use most of what Qt offers me in terms of resources, all the classes for maximum compatibility between platforms. In this case I wanted to do this “pretty” design where everything is handled by different classes. There’s a catch, you meet “unexpected” corner cases where you just set scratching your head wondering why is it like that.

I have a class, let’s call it A:

class A : public QObject
{
    Q_OBJECT
public:
    A(QNetworkAccessManager* nam);
    ~A();
    void process();

private:
    QNetworkAccessManager* nam;
    void processFeed(FetcherReply* fetched);

public slots:
    void finished();

};

So when I put it in a Qt container

QList<A> list;
list << A(nam);

It happens that there’s a implicitly deleted copy constructor on behalf of QObject, which the documentation covers everything so far. Later on I work on a solution of just declaring the copy constructor myself and copying QNetworkAccessManager pointer to the copied class. It happens that that doesn’t go well because NAM doesn’t allow it.

Like I’ve said before, I’m really green behind the ears when it comes to these types of issue. I think part of the problem was thinking of some sort of grand design for the application when I should have aimed for a simple and flexible design rather than going Java.

C++ is undeniably full of surprises. This problem took me a while to admit defeat because I hate admitting defeat. I did learn some things to be aware of later on. Yet, I’m sad that I couldn’t break through the issue myself.

The road to become something decent is thorny as hell.

Working with YouCompleteMe + Vim + Clang/Cmake + Tmux

Recently I’ve had this idea of using Vim to continue development on my application. Most of the development is done in my desktop where I sit and fight wars with QtCreator. Now, there’s something I really enjoy about using YouCompleteMe is on how incredibly fast it is. The subsequence algorithm it uses is perfect (for me) as I can “lazy type” the things I want, something I can’t do in QtCreator autocomplete because it doesn’t have the same search mechanism as YCM.

Another reason is because QtCreator FakeVim isn’t that good; no matter how much I use it there’s always something lacking.

All you need to do to get this working is

  • Use CMake (… well, not really, cmake just makes it easier with CMAKE_EXPORT_COMPILE_COMMANDS to be ON either as a switch in your cmake call or as a variable in your CMakeLists.txt
  • Use clang, as far as I know it doesn’t work with GCC.
  • Have some basic knowledge of YCM extra configuration file.

It works incredibly well.

C++ Starter: Memory leaks

C++ Adventures is a section where I mostly speak of my encounters and struggle while learning the C++ language. This section by no means may contain insights of C++ as a language, or any factual content that may be used as a point of discussion. I’m just a penguin on a journey.

Yesterday I spent some time hunting a memory leak that was caused in a separate thread from the main GUI one. I noticed the memory first almost by accident I had the system monitor opened and with a quick glance I noticed my application had sucked 1.4GiB of ram by letting it poll through over 64 sites per second. That caused a collection of unmanaged QNetworkReply to pile up.

The way I got around to fix it I believe isn’t the “correct way” but it works for me. Hopefully someday someone will tell me what I was doing wrong, sadly I don’t know anyone I could befriend and chit-chat about my encounters.


void SomeClass::requestFinished(QNetworkReply* reply) {

   // process data
   reply->setParent(0); //isolate from parent
   reply->deleteLater(); // let Qt handle the rest
}

Leaving your network replies is bad. Even Qt documentation states that the developer has to deal with each reply disposal. It can get really ugly fast if you do constant polls (2-3 seconds) with QNetworkAccessManager and leave things unmanaged.

Now, another subject I wanted to talk about is memory usage and the root of all evil that is premature optimization. Don’t worry, I haven’t fell into a pit of despair after running into my first memory leak.

Lately, I’ve been pondering that on the GNOME 3 environment my application, stripped out of networking stuff I’m working on consumes 18MiB memory, but once I add the networking side it bumps to 24MiB. Where am I going with this exactly? Well, I’ve been pondering on how a person can exercise mindful techniques to not let your application use something more than 80MiB+.

Here’s the thing though, 20, 60, 80 MiB is nothing these days. For a feed reader it might look awkward. At first I felt like 25MiB seemed too much and I’m not even done with my application. Worrying about it is not something I’m constantly doing though.

My initial views on QML

My preconceived notions of technology have led me to really stupid decisions in the past. I’m a fool, a blithering fool.

With that opening I hope to at least share some thoughts on QML. My first view on QML wasn’t proper, it was all doom and gloom when I saw QML was some sort of hybrid monster coming to get you with JavaScript. And JavaScript have left me a bit bitter when it comes to debugging and organization in general, more towards debugging though. Debugging is what we do literally every day, there’s no such thing as write 300 LOCs and call it a day.

And I was led on with that thought, my dislike of JavaScript kept me away from trying QML for a while. Until I saw this introduction video.

After finishing the video there was this surge of ideas coming to me. What works? What doesn’t work? What should I try first? How to redistribute this later on? How to take care of cross-platform in a way that sucks less? Exciting times, really.

Now let me mention JavaFX for a moment before Sun Microsystem “killed it” in favor of a traditional API. QML and JavaFX shares similarities. QML, I feel, has the upper hand in some ways.


import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.geometry.Insets;
 
var list = ["apples", "bananas", "oranges", "pears", "cabbage"];
 
ScrollView {
  width: 250
  height: 250
  managed: false
  node: VBox {
    padding: Insets {top: 10, left: 10, bottom: 10, right: 10}
    spacing: 10
    content: [
      PasswordBox {promptText: "enter password"}
      Separator {}
      ChoiceBox {
        items: list
      }
      ListView {
        vertical: false
        items: list
      }
    ]
  }
}

Taken from Steve On Java

That was JavaFX before it got killed. I still remember when it was first announced I got all excited because building UI applications in Java wasn’t exactly a walk in the park. It was hard and there wasn’t a “best practice” guides to keep me informed on how to manage each guide and how to see each object. I feel like Qt documentation explains Qt Widgets UI elements way better than other UI toolkits I’ve used, which isn’t many by the way.

But, in a way JavaFX script shouldn’t have died.

On the other hand we have this beast the Qt Team developed. A scripting language that could communicate using JavaScript, QML, and C++ and the things it does blows my mind.

So, my initial views on that were; “My God, it’s going to be hell communicating with the C++ backend”. It turned out to be a not so bad experience. You could even expose C++ classes to the QML and register them, and even protect some of the methods you didn’t want to share.

Most importantly, the ability to make your application support scripting. Bringing a whole set of APIs in your core C++ application and expose it to JavaScript sounds like I’ve won a trip to Disney land with all expenses paid.

Wrapping it up, I’m hoping to cook something good for QML and I’m really looking forward to see what I can do!

C++ Starter: I’m still awful

The most awful thing you can do is mistake C or C++ as your typical high-level language where’s everything is managed for you. Sometimes the hours spent in figuring things out can be incredibly rewarding and every little breakthrough I make, while not remarkable in comparison to other people who have been in the grind for far too long; means something to me.

I spent too much time beating around the single question of “when to use references” and “when to use pointers” after I was bit on a really simple problem.

It turns out that my naive thought of passing by reference was okay. Which backfired almost instantly as I needed to pass the whole pointer else the API wouldn’t work correctly. In this case I’m talking about QNetworkAccessManager. I’ll admit I’m still wet behind the ears, even though I get most of the basic concepts things like pointers and references always leaves me scratching my head for a while because I’m not used to care about the lifetime of an object. I think the biggest doubt I have is “why couldn’t I convert the reference back to a pointer as it was before”. Which I tried, but… the errors the compiler threw were alien to me, for now.

Discovery requires experimentation, I’m afraid. I guess this fool here will eventually find an answer to my question, eventually.

And that’s the gist of it. In languages like C or C++ you have to care about the lifetime of objects. A garbage collector won’t be looking out for you if you leave an object be.

I’m okay with struggling; I will keep pushing forward as always. The learning process in this one has been challenging so far; I’m just glad that I keep winning the small battles. Maybe in six months I’ll win the war, who knows?

C++ Starter: A new road ahead

I’m spent. Pretty much all day I’ve worked to migrate from Ghost blogging platform to WordPress, and you know what? It was worth doing it. I’ve learned from mistakes, really stupid mistakes I’ve come to realize later on. And yet, I still have energy to talk about something I’ve been building for a few weeks now.

Maintaining interest in a project is really hard, heck, I have an stalled project called Lafarel because I gave up on the belief that it was going to be useful. The concept was weird after all, maybe if I start working out the kinks of what made it stall in the first place.

As of this month I’m working on a software application called FeedPal. While the screenshot contains nothing, a lot has been done internally!

FeedPal

You guessed right, it’s yet another feed reader application that will come into play. I’ve been pouring over 3-4 hours a day(maybe even more than that) on QT5 documentation, C++ references, and a lots of brainstorming to provide a solid experience of how articles should be presented to the user.

A few key features I’ve been polishing

  • OpenSearch integration
  • Exporting articles to (PDF, ODT)
  • Visual presentation
  • and other features that for now I’ll keep quiet

Why C++? It’s a feed reader for pete’s sake! You could have done that in Ruby language implemented on NodeJS running on the JVM!

If you haven’t come to realize I’ve been pushing forward to learn C++ for quite a while. I’ve been looking for open source projects to participate, yet I keep going back to square one.

After moving away from Ghost I’ve come to realize something very important is that there’s always a market for everything. A feed reader may very well be dime in dozen, yet we can’t predict the future on how the community embrace it. It could be the next top application, or maybe not.

I believe that developers shouldn’t be too opposed to build software that already exist, sometimes you can polish the wheel even better. Yet, there’s a strong opposing view that people shouldn’t reinvent the wheel.

There’s always room for improvement.

C++ Adventures: `const madness`

It’s been an incredibly productive week for me in terms of soaking myself in C++ dark holy waters. I gave up on the idea of having “well-written” C++ in the sense that I don’t think I can get this right this year. I need to read a LOT of code before I can get the gist of writing C++ in an acceptable manner.

By what measure would it be acceptable? Obviously not by internet “standards”, at the very least I want to feel peace of mind that I’m not creating a tiny little black holes every time I compile an application.

An example of what I mean: (explanation taken from IsoCPP.org)

What’s the difference between “const X* p”, “X* const p” and “const X* const p”?

Read the pointer declarations right-to-left.

const X* p means “p points to an X that is const”: the X object can’t be changed via p.

X* const p means “p is a const pointer to an X that is non-const”: you can’t change the pointer p itself, but you can change the X object via p.

const X* const p means “p is a const pointer to an X that is const”: you can’t change the pointer p itself, nor can you change the X object via p.

At my stage, I shouldn’t worry about things like these right now as I’m not building a library or complex code that requires that. However, I can’t really turn an eye on it and pretend it doesn’t exist either.

Thus, for me this issue would be best to attend to as it happen.

In the meantime, I’ve been working my brains off studying Qt Framework which I believe will really help me in the future. I finally feel comfortable working with it even though what I write in C++ feels incredibly messy.

That said, I’m looking forward to new challenges.

C++ Adventures is not over. Soul searching, however, is still ongoing.

What’s up! Fellow readers, if I have any.

So, basically I’ve been chilling out; well, not completely. I’m still taking care of a few real life stuff. I did get to play a few games and watch some TV series.

I needed the break, plainly simple. C++/Qt5 managed to overwhelm me, and that’s okay. You won the battle C++, that doesn’t mean you get to win the war. The funny thing about C++ is that once you think you understand it, somehow it manages to confuse the heck out of you at the end.

I’m somewhat back, meaning I’m becoming better and better handling aspects of myself that I’d love to get rid of. Bad habits die hard.

That said. There will be a domain name change coming soon. And I’m going to hate every bit of it. Why? There are links linking back to this very domain from other linux communities. I know how to set up a redirect through Nginx (or apache for that matter); easy task, just not one that might cover all the issues.

Only thing I’m going to be yelled at is “I USED WGET AND THE DOMAIN STARTED REDIRECTING TO THIS ONE.” Sorry about that, in advance. This is the last domain name change I’ll do. Pinky promise.

I have some subjects to talk about as well so hopefully I’ll go over them next month. I’d like to do a theme change.

I know this post is messy, it’s supposed to be. Hard to write a post about random events and link them together.

See you people soon enough.

C++ Adventures: QT5 and CMake

Lately I have been learning more and more about CMake, at first sight CMake looks like one of those build tools that you wouldn’t want to mess with because it can get quite messy when you start introducing conditions to your project.

I’ve been organizing the project structure of an application I’m working which I’m hoping to release this November. My main aim was to release it for Windows 10 which is the upcoming version of Windows set for summer. Personally after seeing the improvements of Windows 10 I can’t wait to use it myself.

That’s another subject to talk about later though. Configuring CMake to use QT5 isn’t hard, however if you are a novice like me with this build system then it becomes obvious that you have to research a bit more about it.

The first structure I came up for the project was this:

/ (root)
/Include (headers)
/Include/[modules] (headers)
/Sources
/Sources/[modules] (headers)
/Tools/ (whatever scripts needs to be done, let’s say packaging)
/Documentation

Which means letting CMake recursively search each folder.

What’s been worrying me is that personally I want to separate the UI files from QT Designer from the sources files. I have yet to write a rule for that in CMake.

Why worry about project structures? Well, for one I know that sooner or later I will have to refactor and I don’t really fear refactoring. However, it becomes clear that if I want to keep working on this project I need to have folder structure that sucks less, simply put I don’t feel like wasting time moving files over and over again. Making the project modular also helps me separate the concerns of what a module should do and what it should provide rather than throwing everything in a /src folder.

After setting a basic structure I was able to compile the application. There’s still a lot more to be done though, such is development.