Showing posts with label c. Show all posts
Showing posts with label c. Show all posts
Thursday, 17 November 2022
Hands up! Measure! And keep it simple!
Thursday, 7 February 2013
Why I Will Not Use Java
This post is quite old. I wrote it back in 2010, when I realized Java's main drawback is its verbosity. I didn't expand my thoughts, 'cause I was too engaged at work with C, Objective-C and Python. But in these days I read some articles about Java 8 and I felt very disappointed, 'cause it lacks some features, some snippets and doesn't resolve Java's main drawbacks.
Java Language is Verbose
Java Language is verbose, in the worst way you can say it, mainly for two reasons.Wednesday, 30 November 2011
The End of Multi Threaded Programming
I warn you: this is a provocation. I really want to have replies to this post. Because I'm talking about one of most famous themes for computer-science students: threads and multithreading programming.
A special thanks to Andrea "MEgrez" Talon whom solved some doubts I had about Node.js
A special thanks to Andrea "MEgrez" Talon whom solved some doubts I had about Node.js
Etichette:
c,
c++,
java,
Programming,
Python,
Real-time,
Server Side,
Web
Wednesday, 23 November 2011
Build your C/C++ programs everywhere with SCons
Maximum Power!
In these days I'm trying to realize a small and portable game engine using SDL+OpenGL, fascinated by their power. I begun writing some C files and a simple Makefile.
Portability is a fundamental requisite, so I decided to move to a portable building system. I thought CMake could be a good choice, mainly because it's used by several open-source project: KDE, Inkscape, OGRE, MySQL use CMake. So, I decided to write my platform-indipendent CMakefile. It was one of most boring and error-prone task I've ever saw. After some days, I still can't have a functionally CMake file: I've got less problems writing then a python script for compiling it. Frustrating.
Etichette:
c,
c++,
free software,
Objective-C,
opengl,
Programming,
tutorials
Thursday, 13 October 2011
Farewell, Master
Today I read the latest sad news. Denis Ritchie, co-writer and co-ideator of UNIX and C programming language, died at 70.
Thank you for your immense contribute to computer science.
int main(int argc, char** argv){ printf("Farewell mr. Ritchie.\n"); printf("You made our tools.\n"); printf("You made the True Operating System.\n"); printf("You made us programmers.\n"); printf("You made us hackers.\n"); return 0; }
Tuesday, 5 July 2011
iPhone SDK Troubles: a missing feature in XCode 4
XCode4.0.2 hasn't got a "Search and Replace in Selection" tool. It's one of most important tools for some very boring tasks, such as adding a @synthesize to hundred of lines or using the same lines to initialize them with a [[NSString alloc] init];
I hope Apple soon adds it: I wouldn't to continue switching between XCode and VIM to replace some text!
I hope Apple soon adds it: I wouldn't to continue switching between XCode and VIM to replace some text!
Etichette:
Apple,
c,
c++,
IDE,
iPhone SDK Troubles,
Objective-C,
rants
Monday, 18 April 2011
Nobody can choose how to trash
Today I read an interesting letter sent from Ted Evans of Techrunch to Steve Jobs. He said
Please give us garbage collection
When you say "garbage collection" you always think to Java, to its slowness and to its inefficency. I think, instead, about days spent to detect a memory-leak error, when I was near to the deploy deadline. Working with iOS is wonderfull, but can also gives you headache if you aren't enough careful. Useless to say, when you have to realize a 4000-rows-of-code in two days, it's hard to be "enough careful"!
Ok, I admit a garbage collector could makes programs slow. But if I could use it when I want and if I could dealloc objects when I want, I could realize a "slow" version in time. Slow as you want, but it will not crash because of memory overflow, segmentation faults, ecc.
In next version, with more time, I could analize the code, optimizing memory use and detecting overflows and errors.
So, yes: I would like a Garbage Collector. But activable only when I want.
PS:
Can you recognize the man on the "wanted" poster on this TechRunch article? Well, our prime minister (I am italian) isn't very admired in other countries
Thursday, 3 March 2011
Never Reinvent the Wheel
In these days I'm writing a small roguelike. I started it in Java, but soon I moved to LÖVE, a framework for 2D games based on OpenGL and Lua. After some days I've got "something working" (moving camera, smooth characters, entities, doors, items) so I reflected about the "reinventing the wheel anti-pattern".
As a programmer, I enjoy to write code. I tried many times to write an OpenGL 3D engine; I tried many times to write a 2D platform game engine. But after all, is a good idea to write yourself all this code when somebody already did it?
Obviously no, but believe me: to reinvent the wheel is a strong temptation and, often, we follow it unconsciously.
Don't invent your own configuration language: there's already Lua.
Don't write your own 3D engine: there's Panda 3D, Crystal Space, Irrlicht Engine, Ogre 3D, the various ID Tech (now they're under GPL).
You'll earn time and you'll see result sooner then you think, allowing you to give more attention to the most important things of your program.
As a programmer, I enjoy to write code. I tried many times to write an OpenGL 3D engine; I tried many times to write a 2D platform game engine. But after all, is a good idea to write yourself all this code when somebody already did it?
Obviously no, but believe me: to reinvent the wheel is a strong temptation and, often, we follow it unconsciously.
Don't invent your own configuration language: there's already Lua.
Don't write your own 3D engine: there's Panda 3D, Crystal Space, Irrlicht Engine, Ogre 3D, the various ID Tech (now they're under GPL).
You'll earn time and you'll see result sooner then you think, allowing you to give more attention to the most important things of your program.
Friday, 19 November 2010
The power of a "Singleton"
«Please, excuse me if I didn't update my blog in these days. I was so busy in some activities, both at work and for my movie. Yesterday, with Fabio, I looked for a good place to realize some scenes. We were lucky!»
In this post I'll talk about singletons, last design-pattern I found. If they're necessary in Cocoa, they're also usefull in other programming contexts. What's a singleton, exactly? On wikipedia it's defined as «the instantiation of a class to one object» and well, it's right.By a programming point of view it looks like (in Java):
You see, when you're using a singleton, you have just one instance of this object (here it's called shared_singleton). You can get a reference to this object with the getSharedSingleton static method.
In Cocoa touch, singletons are the most confortable way to have a shared resource; global variables, (very used in C) aren't good as a singleton. In Java you can insert them easily in a multithreaded context, just adding the synchronized keyword. Singletons are very good to share read-only data and they can be used in every object-oriented programming language.
Singletons could be dangerous, because (if they're not well designed) they could know too much about other objects, can grow in functions if they're not well designed a can give throubles in a multi-threaded environment. A detailed description about dangers of singletons abuse is Use your singletons wisely by J. B. Rainsberger, employed at IBM. It's an interesting lecture if you are a programmer. Another good lecture is Singleton Pattern description, where there's also some example of "Singleton Abuse".
![]() |
A singleton doesn't need 1.5 GW |
class MySingleton{ private static MySingleton shared_singleton=null; private int counter;/** * Private constructor */private MySingleton(){ counter=0; }/* * Increment counter */private void Increment(){ counter++; }/* * get the singleton */private static MySingleton getSharedSingleton(){ if (shared_singleton==null) shared_singleton=new MySingleton(); return shared_singleton; } }
You see, when you're using a singleton, you have just one instance of this object (here it's called shared_singleton). You can get a reference to this object with the getSharedSingleton static method.
In Cocoa touch, singletons are the most confortable way to have a shared resource; global variables, (very used in C) aren't good as a singleton. In Java you can insert them easily in a multithreaded context, just adding the synchronized keyword. Singletons are very good to share read-only data and they can be used in every object-oriented programming language.
Singletons could be dangerous, because (if they're not well designed) they could know too much about other objects, can grow in functions if they're not well designed a can give throubles in a multi-threaded environment. A detailed description about dangers of singletons abuse is Use your singletons wisely by J. B. Rainsberger, employed at IBM. It's an interesting lecture if you are a programmer. Another good lecture is Singleton Pattern description, where there's also some example of "Singleton Abuse".
Tuesday, 16 November 2010
The Last of the Patriots
The Game
Paul Davis is a game designer and a programmer. He worked on "Manhunt" and "Grand Theft Auto" as level designer. Two years ago, following a link, I found his site, «Lastofthepatriots.com»(unlucky, now it's a dead-link), where mr. Davis hosted the omonimous project. In «Last of the Patriots» (I and II), he created a game engine from scratch, using OpenGL and Audiere as base. His main objective was to write a game focused on story, moral decision and player involvment. The result was «Last of the Patriots», which can be defined as a "Visual novel with a Zelda-Like visualization": you will not shot so much and there's no special-FX or 3D graphics. Last of the Patriots has a story, based on a movie script. You will be surprised about how your feelings will change playing with this game. "Last of the Patriots" is an interesting game experience and I suggest you to give it a try.
The Technical Notes
After a while, I sent an e-mail to Paul Davis, asking him some technical informations. I was really interested about indipendent video-game development and I recived his reply with enthousiasm. I was not disappointed: mr. Davis was exaustive and well prepared.
First: he used OpenGL for graphics and Audiere for the audio parts. A port to other operating systems, anyway, shouldn't be easy, because the input is managed by the win32 API (OpenGL hasn't a great input manager). All the graphics was realized using a 3D program to modelize and animate. Every frame is a shot done to this animated models.
Game logic is realized with an embeded scripting engine written by Davis. I can't say so much about that, because I didn't find any script.
The whole game engine it's coded using C (no C or Objective-C) for personal choice (he prefear to use C). He admits, anyway, for a similiar game, Java could work well.
Conclusion
I encurage to play with with «Last of the Patriots» and its sequel, because some misteries (first of all, the title) are explained. I don't know if the official website will go online again, but you can still download the binary from this link.
Last of the patriots is a very particular game. Give it a try: it could open to you new interesting prospectives. Mr. Davis said he write it to focusing on story instead on graphics.
He did it.
Paul Davis is a game designer and a programmer. He worked on "Manhunt" and "Grand Theft Auto" as level designer. Two years ago, following a link, I found his site, «Lastofthepatriots.com»
The Technical Notes
After a while, I sent an e-mail to Paul Davis, asking him some technical informations. I was really interested about indipendent video-game development and I recived his reply with enthousiasm. I was not disappointed: mr. Davis was exaustive and well prepared.
First: he used OpenGL for graphics and Audiere for the audio parts. A port to other operating systems, anyway, shouldn't be easy, because the input is managed by the win32 API (OpenGL hasn't a great input manager). All the graphics was realized using a 3D program to modelize and animate. Every frame is a shot done to this animated models.
Game logic is realized with an embeded scripting engine written by Davis. I can't say so much about that, because I didn't find any script.
The whole game engine it's coded using C (no C or Objective-C) for personal choice (he prefear to use C). He admits, anyway, for a similiar game, Java could work well.
Conclusion
I encurage to play with with «Last of the Patriots» and its sequel, because some misteries (first of all, the title) are explained. I don't know if the official website will go online again, but you can still download the binary from this link.
Last of the patriots is a very particular game. Give it a try: it could open to you new interesting prospectives. Mr. Davis said he write it to focusing on story instead on graphics.
He did it.
Tuesday, 26 October 2010
HipHop: emotions no-stop
![]() |
Mhh... there's something strange.... |
Some months ago, Facebook annunced its new "HipHop" technology, used to speedup its servers. HipHop is a translator: when a page is requested for first time, HipHop transforms PHP source code in to a C++ source and then compiles it into native code with g++.The executable then is launched:its output is passed to the webserver.
Haiping Zhao, senior engeneer and HipHop chief, said HipHop speeds up to fifty percent Facebook servers. No bad, really. So, will we start to develop with HipHop in mind? I don't think so.
HipHop born with a specific target: to increase performances of one of most visited sites on earth. But, after thinking about it for some weeks I realized that better solutions could exist. Assuming as fundamental requisite that is impossible to rewrite ALL Facebook in another language and that most of programmers involved knows only PHP we can:
1. write a PHP-to-Bytecode interpreter. JVM on server side is great: it's scalable and it has a JIT.
2. create a front-end to LLVM. LLVM is a Virtual Machine AND a compiler. Apple is founding LLVM project, probably to use it as default compiler for its systems. LLVM supports multithreading.
HipHop technology seems to me as a return to the CGI. After ten years of mod_php (created to avoid CGI), Zope and other ways to reduce the use of CGI, we return to the root of web programming.
In my humble opinion, HipHop looks like more as a "patch" than an "entire solution". Facebook's engineers know well their work and they developed Cassandra DB from ground to up. A great work, well designed and well implemented (Java for scalability and fault-tollerance; replication; choice of a non-relational schema, ecc.). It sounds strange that Cassandra and HipHop came from the same home, because they seem too different. I think Apache Foundation is more coherent: Apache developers work on server-side with Java, with some exceptions in client and C/C (such as Xerces and log4cxx).
I have no doubts that Facebook's administrators know well what's better for their business and I have no doubts they studied with attention to choose the best solution for their problem. But their solution seems very strange to me, and I would like to understand why they choose to create HipHop.
Monday, 18 October 2010
La trappola del C++ (seconda parte)
«Non è facile portare un satellite in orbita» Lo Space Shuttle Atlanits (STS-27) Immagine fornita da Wikimedia Commons |
Saturday, 16 October 2010
La trappola del C++ (prima parte)
Il titolo è provocatorio, lo dico subito. Se pensate che qualsiasi programma è meglio scriverlo in C++ dimenticate l'esistenza di questo post, visto che vi farà solo venire acidità di stomaco.
Se, invece, siete disposti a in discuterne, mettetevi comodi: ci sarà da divertirsi.
Subscribe to:
Posts (Atom)