Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Thursday, 17 November 2022

Hands up! Measure! And keep it simple!

At the end of this post I will expose an example of a speedup of 8000x. This means that a program that at first took almost five hours to complete, ended up in two second.
A ratio of 8000:1.
Pretty impressive!

Wait! What?!

Monday, 24 October 2022

Why C++ is difficult

C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do *nothing* but keep the C++ programmers out, that in itself would be a huge reason to use C.

Source is here. Many of you will recognize these words: it's a piece of Linus Torvalds' rant aganist C++, when some developers asked him to move Git from C to C++.

Monday, 4 January 2021

Makefiles Returns

Doing stuff: the good old way

I often write Makefile(s) for my projects, even when they’re in some scripting language. This because the good old, humble make is installed almost everywhere and its simple syntax does one thing and does it well: doing tasks according to dependencies.

Wednesday, 18 November 2015

A Way to Deploy Python Programs

[...]we will use Java, because a jar file is easier to deploy.
This sentence occurs sometimes where I work. In this multi-environment place, a easy way to deploy your software is a fundamental requirement.

Wednesday, 3 December 2014

Why a Build System in IDEs Era?

Some friends of mine criticized my old post «Build your C/C++ programs everywhere with SCons», arguing a build system is useless in modern world.


Tuesday, 17 June 2014

What I miss in Python Game Development


As I said before (and I repeated), if I start a new project, I prefer to work with Python, 'cause I like its huge standard library, its portability and its syntax and this is true for every new project I do for work: such as "building netcdf files", "analize meteorological datas", "manage databases". But I had a big problem for a personal project, a long dreamed chimera never really realized: a videogame. I thought to build a simple shooter, something like the old "galaga" or "space impact", using hardware accelerated graphics for great effects, such as particles and flashes. There are many schools of thought on game development under Python: there's PyGame ones, Pyglet, Pandas, ecc. I would like to talk with you about actual game development in python and reflect about my needs

Thursday, 17 October 2013

Mac OS X, Python, PySide and Matplotlib

In these days I'm working on Python application for manage some metereological datas. It uses PySide for the GUI and Matplotlib to plot some useful charts. Unluckily, I had some troubles to add this last library. After some work, I found a solution. This post is a brief guide to my little oddity on using PySide and Matplotlib on a Mac OS X environment.

Monday, 18 February 2013

Aqueduct on GitHub

If you're a writer and you like to write screenplays for theatre or movies (as me), maybe you know Fountain, a markup language realized to give you a simple, easy and elegant way to manage your scripts.

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.

Sunday, 6 January 2013

Lua vs Python or Embedding vs Extending


Another (in)famous comparison!
At least once in your programmer career, you will face the need to add a scripting language to your program. Many famous programs use a scripting language: Unreal, Quake, Emacs, Blender 3D and many games. But, when you decide it and when you start to project your implementation, you face a terrible dilemma: should you make a program with a interpreter or functions for a interpreter? This crossroad is the "embed vs extend". I'll talk about my personal opinion and how this dilemma is equal by Lua vs Python comparison.

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

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.

Wednesday, 14 September 2011

iPhone SDK Troubles: ios SDK blurry fonts

A very annoying thing is when you programmatically create contents for a UITableViewCell and text in UIlabels appears blurry. Why? The answer is simpler than you can think: you positioned your UILabels in the wrong place. Probably, you positioned your UILabel:
//At allocation time
UILabel* l=[[UILabel alloc] initWithRect:CGRectMake(x,y,w,h)];

//or after
l.frame=CGRectMake(x,y,w,h);
Now, be careful: what's the meaning of (x,y,w,h)? They're floating point values. When placed in a UIView, they must have no fractional part. If you specify it with (e.g.)
(1.0f, 3.0f, 200.0f, 400.0f)
your label will not appears blurry. If you calculate UILabel's frame, you must call floor function to force to zero fractional part.
float a=1.0f;
float b=3.0f;
float c=200.0f;
float d=400.0f;

l.frame=CGRectMake(
        floor(x/3.0f),
        floor(y/3.0f),
        floor(w/3.0f),
        floor(h/3.0f)
    );
Texts appear blurry when coordinates aren't approximate to nearest integer. Floor force this approximation. Now your text will appear sharp as a japanese sword :)

Tuesday, 9 August 2011

iPhone SDK Troubles: Rotating scrollview image gallery



Everybody love iOS interface and its "magic" appeal: fluid rotations, fluid swipe, ecc. A iOS programmer knows that there's a lot of work under that magic. If you try to realize a simple image gallery, you'll have some surprises when you'll try to rotate it:

  1. your image will not be located on view's center, but on a corner.
  2. if you forced your gallery to scroll to a certain page with scrollToRect, then you'll see all your precedent images in a fast scroll, even if you set parameter Animated to NO
  3. if you need to scroll after rotation, you'll see a rotation around a corner
Solutions I found are:
  1. Point 1: when detecting a rotation, (willRotateToInterfaceOrientation), you have to resize:
    • Images on the scrollview
    • scrollview content

  2. Points 2 & 3: you must cover gallery's scrollview with a UIImageView containing current gallery image, hiding all scrollview animations. The "cover" will rotate around screen center, giving a more professional (and Apple) look.



Thursday, 28 July 2011

iPhone SDK Troubles: Error from debugger: Error launching remote program: security policy error


When I started programming with Cocoa-Touch a guy who teached me Objective-C's basis said «Everybody loves Cocoa. Not much people loves XCode».
Forgetting some boring and stressful troubles (mainly about memory management), I agree with him, because last "iPhone SDK Troubles" came from XCode. It gives me this error:

Error from debugger: Error launching remote program: security policy error

It taken me a lot to resolve it, because it seemed an error related to Info.plist or a bad-configured provisioning profile.

Instead it was easy: just delete all expired provisioning profiles from your device (iPhone/iPad). Go to Configuration->General->Profiles and delete them.
I was tired, so I deleted all profiles and I rebooted the device, but after I was able to install applications from XCode to iPad.

Friday, 22 July 2011

Pyglet on Windows 2000. Yes, you can!

So, you're a "pythonist", right? And you get tired of pygame, right? And you want to play with pyglet but it doesn't work beacuse there's an error with GDI+?
Relax, man! I'll explain you how to resolve ;)
  1. go to MSDN site and download the GDI+ packages
  2. Decompress it on a directory. It's not important wich one: we have to get the gdiplus.dll file
  3. Copy gdiplus.dll from /asms\10\msft\windows\gdiplus
  4. Paste it on your python directory. I have it on C:\python26.

It's all! Happy coding!

Wednesday, 13 July 2011

«From Python to Ruby» aka «Yet Another Infamous Comparison»!

In these days I'm interesting about Ruby and Ruby On Rails. I already know PHP and Python, but Ruby seems more active, widespread and interesting. For "interesting" I mean PHP still appears to me as a easier Java without compilation and classpath. Some friends of mine use Symphony, but I am not so enthusiastic about it. I like Python's abstraction level, but I admit it has too many web frameworks and none of them seem "cool" enough.
Rails, instead, uses an high level language (Ruby) and creates a homogeneous, well designed and complete environment for web application development.
These are my first impressions: maybe I am wrong.

This post is written for another religion war: Python vs Ruby. I belive it's a war without sense and I think it's usefull learning both.

Always learn at least one scripting language

It's fundamental to learn at least one scripting language. It could be lisp, javascript, python, ruby, perl, ecc. But it must read/write files, opens sockets and do everything a real language must do. It will help you to write some usefull scripts (e.g. create and populate a database from text files, download and save XML from network to local disk, ecc.)
Will learn more than a language will help me? yes! Because...

...you must use the more confortable tool...

...for a specific task. C and C++ are usefull for real-time applications and for videogames. They're not very good to write CGI or web applications. Java is good on servers, but I think isn't good for heavyweight audio manipulations.
I found myself comfortable with Python in many cases, but it is very likely I will use Ruby more often. Remember: the silver bullet is an anti-pattern. Learning more languages will give you more instruments to work better and faster. In programming there's not a Holy Grail, just the right tool in the right place.

Tuesday, 28 June 2011

Eclipse vs Netbeans

Oh yes... another (in)famous deathmatch between two developers tools. Eclipse is supported by IBM and uses a custom library to give an GUI, the famous Standard Widget Toolkit (SWT). Netbeans is based on Swing and is sponsored by Oracle.
Two years ago I switched from Eclipse to Netbeans, just for Netbeans' GUI editor (Metisse), a program I waited for long.
Soon, I discovered some things I liked of Netbeas:

  1. An easy way to install plugins
  2. A powerful refractor tool

Despite it's written using Swing, Netbeans works well. I still have doubts on developing applications using Swing, but Netbeans demonstrates it's possible. It's well integrated with desktop (Mac OS X, Windows 2000 and Ubuntu).

BUT (and it's a recent news), Eclipse Foundation releases a new version of its IDE, Indigo. Indigo has very interesting features, and seems it's going to be very near to Netbeans.
I'll examine it better next days. I'm very curious about it.
Meanwhile, I continue using Netbeans, because I'm used to work with it and because (as I learned some weeks ago), it's better to wait a bit before start using a new major version.

Wednesday, 1 June 2011

iPhone Tutorials - "Duplicate Symbol _OBJ_IVAR_"

I am working on a personal review about XCode 4. Please, be patient!

XCode 4 gives me many troubles. The last one was a linker error

Duplicate Symbol _OBJ_IVAR_ a class

What happens?

  • Maybe you declare #import "Classname.m" (with a .m instead than .h)
  • XCode lists "Classname.h" and "Classname.m" two times. You have to "remove reference" for a copy from XCode.

It seems XCode4 gives many problems to iOS developers. I'll talk better in another post.

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