Jump to content

  • Log In with Google      Sign In   
  • Create Account

Felix Ungman

Member Since 19 Nov 2007
Offline Last Active Today, 08:36 AM

#5170132 Can somebody explain this code to me, please

Posted by Felix Ungman on 29 July 2014 - 12:06 PM

I don't know perl, but isn't it supposed to be a write-only language?

#5154331 Member variable as template paramter

Posted by Felix Ungman on 17 May 2014 - 04:11 PM

Ok, the example maybe didn't illustrate what I meant, a better one might be:  

class ButtonWidget
    std::function<void()> _onClick;

    void SetOnClick(std::function<void()> action) { _onClick = action; }

    void TrackClick()
        // ...
        if (_onClick)
        // ...

Then you can fix the data you want to hold in the lambda:

for (int i = 0; i < n; ++i) {
    int buttonNumber = i;
    button[i]->SetOnClick([buttonNumber]() {

Code is simple but powerful. I don't know how it relates to your framework or how you would need to rewrite it (it seems you use signals both for events and for data bindings, right?), but I've found the technique very useful in my own gui code.

#5153492 Opinion needed: returning values without null checks everywhere

Posted by Felix Ungman on 14 May 2014 - 12:32 AM

Objective-C has an interesting take on this problem. If you have a nil object reference, calling a method is a no-op, and calling a function returns a default value (i.e. zero, false, or nil). Good coding practice is *not* checking the object for nil, but instead just send the message and checking the return value instead. Unfortunately there's no simple equivalent construction in C++.

#5145914 I have some new habits.

Posted by Felix Ungman on 10 April 2014 - 06:12 AM

I have a much easier time thinking of someone with a background with a function based (not functional lambda calculus) experience like C/Pascal will do a better job at designing software than someone with a (bad) OOD background. He or she would use the modules approach of Pascal and apply it to OOP and we would all be happier for it.


I'm sure a bad designer would produce crappy work no matter the methodology. Granted, OOP gives you a richer set of tools to introduce strange and unnecessary relationships, and in that case sticking to C/Pascal might give you some damage control.


I think the problem here is that when you are learning a new methodology, you write small toy-world pieces of code of very limited complexity. But in the real world, projects grow and requirements change and complexity seems to grow without bounds. With a team of inexperienced developers you tend to get a lot of redundancy (failing to see that different parts of a system share a common concept) and a lot of bad dependencies (such as realizing that another part of the system is doing something related to what you're coding so you do a quick-and-dirty rewiring). Time constraints and deadlines don't make things better.  You need an experienced designer willing to take the time to constantly re-evaluate the design as the system grows.


I am always trying to improve and to know more about OOD (a new improved way) is always interesting.

I highly recommend Evans Domain Driven Design. Beware that it's not a beginners book. Although it has a lot of patterns (OODish or whatever you want to call it), I think the main point is more the process or rather mindset when designing large software systems.

#5126045 MMO Engine Production - Do we create from scratch or use libraries?

Posted by Felix Ungman on 24 January 2014 - 01:42 AM

Do free, previously coded and open source game engine libraries usually allow their creations to be used in projects that charge a monetary, monthly fee for their products?


The issue with open source licenses is not whether you're allowed to charge for distribution or use (most licenses allow it), but whether you are required to apply the license to you're own code too. GPL might actually be fine if you're using a service based revenue model.

#5109384 Using a Notepad in Industry to keep track of modified code

Posted by Felix Ungman on 15 November 2013 - 02:36 AM

As a solo programmer, I've found git far more useful than svn. Once you understand how it works, it's extremely easy to set up, branch off modifications, compare those changes, and merge them together. I would never dream of doing this by hand.

#5108644 Appropriate number of bugs

Posted by Felix Ungman on 12 November 2013 - 04:13 AM

That being said, I never really liked the Agile development model (but this is just me), because it forces you to code fast, without thinking about possible bugs you might be introducing. I also don't like how it categorizes and splits work into fixed, periodic categories (or whatever they're called - 2 weeks planning, 2 weeks developing, 2 weeks testing, then repeat). Since you're not documenting much, just adding tasks, you will end up forgetting details of what was planned before you even start developing. Plus, when it comes to bugs, you really cannot plan for them. I always find it easier and faster to fix bugs as I find them, while I'm still involved in the task I'm working on, even if it's not related to my work. Instead, Agile just forces you to add a new task for the bug and move on.


Agile is not not cowboy coding. If you plan to implement a certain feature, you're not really done with the task until the feature works as expected (i.e. no bugs). Fixing bugs as soon as you find them is a good practice, and it doesn't contradict good agile practices. In the contrary, if you are measuring project velocity (story points per sprint or whatever your measure is) then the earlier you fix the bugs the better you'll be able to measure the "true" velocity. Otherwise you are just borrowing time from the future and adding to the hidden technological debt.


That said, agile may not be easy to do in practice (depending on the organizational culture), and may not be the best approach for every project. On the other hand, I've not find any negative aspects of it in my experience.

#5108422 Appropriate number of bugs

Posted by Felix Ungman on 11 November 2013 - 01:59 AM

One of my lecturers at the university once told a story about a programming course he'd previously taught to a mixed group of both software and hardware engineers. When reviewing the lab assignments he was astonished that the code submitted by the hardware engineers didn't have any bugs. When he asked them about it, they answered "oh, we didn't realize bugs were allowed".


There's only one answer to what's the appropriate number of bugs: ZERO. That's the mindset and the rest is just implementation.

#5107839 Is hacky code allowed in industry?

Posted by Felix Ungman on 08 November 2013 - 03:31 AM

I always found hacky code to fix all the bugs in my game and let me progress faster in my game development process.


I've realized that adding code almost always makes it less clean. And the faster you add new code the faster it gets dirty. There are two solutions:

1) Add code slowly to keep it clean.

2) Add code quickly and then come back and clean it up.


IMHO hacky code is OK if it's used as a stepping stone. Actually, many times I've found that adding a lot of hacky dependencies allows you to use the resulting code smells as a guide to find the architecture.

#5107371 Hosting Online Game

Posted by Felix Ungman on 06 November 2013 - 01:19 AM

I'm also currently comparing host services for a matchmaking server. So far I've looked at Amazon EC2, Google AppEngine and some local cloud provides. Pricing is highly dependent on CPU, memory, and bandwidth needs, and I'm not able to compute costs yet because I'm still deciding what needs to be done on the server and what can by done by the clients or using a peer-to-peer scheme. AppEngine seems simpler to use (no OS admin), but doesn't allow UDP servers (yet?). Amazon has a lot of nice extra services, like database and storage services, that can potentially make the solution more scalable (but the pricing gets more complicated). The local cloud providers simply give you a virtual server and a some virtual storage for a fixed monthly fee.


So no conclusions yet, I will have to continue working out the architecture before I decide.

#5071993 Name of a particular property

Posted by Felix Ungman on 22 June 2013 - 05:23 AM

As you're dealing with data buffer, it seems that the function is some kind of stream writing operator.

#5069993 Developing a cloud service/server for your app?

Posted by Felix Ungman on 15 June 2013 - 11:23 AM

Hard to recommend anything without more details. But I would suggest start by looking into Ruby or Python as the server side language. And depending on the services, pick your frameworks and libraries from that.


On iOS devices, there's some Cocoa http request classes that are easy to use from c++. Not very portable though.

#5068648 alternatives to long else if and switch statements

Posted by Felix Ungman on 10 June 2013 - 06:10 AM

I`m working on a project where there is a massive amount of library/engine files being used from the last project. In quite a few there are crazily long if-else and even nested trailing if-else statements making some changes hard to debug and sometimes it`s hard to see where the missing curly bracket is on compiling errors.


As rnlf points out, readability should be the primary goal. Some techniques:


- Remove reduntant conditions (the most extreme being if (x) … else if (!x) …", but there are other more subtle ones). 

- Move the conditions inside the "if(…)" into separate functions. Try to find good names for those functions.

- Move the statements inside the brackets into separate functions. Try to find good names for those functions.

- Sarch for code duplication inside those conditions and statements and put that into separate functions too. Try to find good names for those functions.

- Try to keep the if-elseif-…-else chain consistent. Sometimes it's more logical to split one long chain into two separate ones. Sometimes you can merge two chains into one.

#5064125 How to structure a game in OOP

Posted by Felix Ungman on 23 May 2013 - 06:24 AM

Yes, it's good practice to put your state inside of objects, even if there's only one instance of the class. The question is of course where to put each individual variable. If you're not satisfied with the architecture but you don't know what to do, one approach is to just shuffle the code around and see what happens. Experiment with merging and splitting classes and functions. Look for new names, and try to make them as concrete as possible. Poke around and see if you find any redundant duplications or code smells. It usually takes a few iterations before the architecture settles.

#5063844 else if question

Posted by Felix Ungman on 22 May 2013 - 08:01 AM

Good questions.


The problem with multiple returns and breaks is usually not that there are multiple exit points, but that the code is so complex that those exit points are hard to see. If the code is simple enough you'll easily see all the dependencies in it. Also, evaluation order usually matters (more often than the other way around).


But you're right that much of readability is a matter of taste. It's easier to read what you are used to read.


Btw, wouldn't the single-return version be something like this: (Not sure I prefer this one though.)

bool operator<(const Date& input) const
     return year < input.year || (year == input.year && (month < input.month || (month == input.month && day < input.day)));