background preloader

Code

Facebook Twitter

State Design Pattern. Intent Allow an object to alter its behavior when its internal state changes.

State Design Pattern

The object will appear to change its class.An object-oriented state machinewrapper + polymorphic wrappee + collaboration Problem A monolithic object's behavior is a function of its state, and it must change its behavior at run-time depending on that state. Or, an application is characterixed by large and numerous case statements that vector flow of control based on the state of the application. Discussion. C++ FAQ. Virtual assignment operator C++ C++ - Why does virtual assignment behave differently than other virtual functions of the same signature.

The Assignment Operator Revisited. The Assignment Operator Revisited by Richard Gillam Advisory Software Engineer, Text & International IBM Center for Java Technology–Silicon Valley If you think you know it all in the C++ world, it must mean you’re not talking to your colleagues very much.

The Assignment Operator Revisited

If I had any pretensions to knowing it all when I wrote my assignment-operator article ("The Anatomy of the Assignment Operator," C++ Report, Nov/Dec 1997), they didn’t last long afterwards. The assignment-operator article drew a huge response, with a lot of people sending me corrections and disagreements of various kinds. The issues have been mounting up, so I thought maybe a follow-on article to discuss the issues would be appropriate. The big mistake One I heard about almost instantly from several people (and which I’m really glad I heard about before delivering a talk on this subject at C++ World) was a rather serious mistake.

C++ Operator: How to deal with operator overloading? Beautiful algorithms. Erlang MMORPG Engine. Although I haven't gotten to that part of my game server, I've tried to design it to avoid any sort of physics, because of the potential latency between a client and the server.

Erlang MMORPG Engine

(I'm targeting mobile users.) The only 'physics' that need to be calculated is when a player changes speed/direction, and you must calculate the path and detect collisions. However, to minimize negative effects on gameplay, both the client and the server 'dead reckon' the position of players in their immediate view bubble. In the client, this is done on a separate thread, on the server, a separate set of processes. Generate List<int> What is the Maximum sizes/numbers SQL Server (32-bit) Bytes per primary key.? - .NET, C#, VB.NET, Sql Server. Qctemplate - An easy to use template engine for C++/Qt. If you are familiar with string template engines like Smarty (PHP) or Django (Python), then you know what template engines are about: to facilitate the separation of application code from presentation.

qctemplate - An easy to use template engine for C++/Qt

Template engines are much less common in C++ than in web development, but things are slowly changing. Today, C++ application need to generate more and more web pages. This is particularly true for Qt programmers since they can embed a complete browser engine (QtWebKit) in their applications. Google CTemplate is such a template system for C++. It is a quite powerful library, but it does not mix that well with the Qt framework, and it is not that simple to use. QCTemplate is a very thin layer above Google CTemplate developed with the following goals in mind: be as simple as possible to use (encapsulate nicely Google CTemplate) integrate nicely into "Qt philosophy": use a qmake project file, be compatible with Qt Resource System, use QString type, etc. Coding Solutions—Immutable Types Are Scalable Types at C. One of the most commonly used types is string, and string is an immutable class, meaning that once it’s assigned the type cannot change.

Coding Solutions—Immutable Types Are Scalable Types at C

To change the state of an immutable class, a new class needs to be instantiated. Developers rarely consider using immutable classes because our logic says immutable classes are inefficient. Yet one of the most used types, string, is immutable. Efficiency can be measured multiple ways, but for today’s hardware efficiency is best measured as code that gets in the way of the processor very little. These days we have processors that can blow the socks off your feet. A scalable class uses the keyword lock as little as possible. Class ExampleSynchronized { public void OnlySingleThread() { lock( this) { Console.WriteLine( "Hello world"); } }} In the example the method OnlySingleThread allows only one thread to output the text to the console. Floating Point. Java Anti-Patterns. This page collects some bad code that may not look so obviously bad to beginners.

Java Anti-Patterns

Beginners often struggle with the language syntax. They also have little knowledge about the standard JDK class library and how to make the best use of it. In fact I have collected all examples from everyday junior code. I have modified the original code to give it example character and such that it highlights the problems. Many of these problems can easily be detected by SonarQube. Some of these may seem like micro-optimization, premature optimization without profiling or constant factor optimizations. If you are interested in how to pogram compiler friendly, look at the JDK Performance Wiki. In the end a lot of your application's performance depends on the overall quality of your code. Compare these scenarios (assume 100MB young generation):