coder and technology lover
Posts tagged programming
jQuery is not a magic… if you think so, you shouldn’t use it!
Apr 28th
I decided to write this post, because I revised a Javascript code realized by a colleague and it was simply terrifying!
It was bad formatted, it had HTML style comments (<!- – - ->) with insignificant or unclear content, missing var declarations and so on.
What I would like to say is that, in order to use jQuery and similar js libraries a mere HTML knowledge is not enough, Javascript is not hard to understand and use as Java, C++ or other object oriented programming languages are, but several things must be clear before to write some code. If you want to use in a clever and productive way such libraries you should at least:
- Understand the difference and behavior of String, Number, Array, Date and so on
- Have a deep understanding of what DOM is and how it works (you should at least know these methods: getElementbyId(), getElementsByTagName(), createElement(), appendChild(), removeChild() and innerHTML property)
- Know what objects and constructors are and how they behave
- Know what a function is and how to create one
- Know events, event listeners and event handlers
- Understand loops
Too much stuff to learn? It’s the minimum to know, there are then prototyping, JSON, closures, XMLHttpRequest and so on…
Javascript is a programming language (not a tool for designers), don’t believe that a call to $.doMagic() will resolve your problems, you have to understand what is behind that doMagic() (at least the foundations) in order to realize concrete stuff… otherwise you will only write “magic spaghetti code”!
Object oriented programming in Javascript
Mar 10th
After several approaches, I finally found an elegant and functional solution to use Javascript in an OOP way, without use third party libraries or use particular tricks.
The objectives I had in mind was:
- Realize a Java/Actionscript-like class
- Provide a constructor for the class
- Implementing public method
- Implementing private method
- Ensure encapsulation (class properties can’t be changed by assigning a value to the relative instance’s property)
Extending Flex’s logging framework to write custom log files
Feb 23rd
In these days I played with Flex’s logging framework and I extended it to write log messages to files, both plain text .log files and dynamic HTML, CSS formatted and Javascript powered files with the ability to filter message type (debug, error, fatal and so on).
The logging framework is a powerful feature that comes with Flex’s sdk and it’s composed by the classes under mx.logging package, which includes the two “subpackages” mx.logging.errors and mx.logging.target.
Java developers should be already confident whit such framework, because logging api are commonly used in Java programming, Actionscript /Flash/Flex developers may find this tool a novelty (as I did).
The objective of logging framework is to provide a tool that offers a far better, flexible and centralized way to debug an application than simple use a lot of trace() callings. With Flex’s debugging framework we are able to print and filtering among different types of message based on their severity, such:
- DEBUG
- ERROR
- FATAL
- INFO
- WARN
We can also print the timestamp of the message and the class it refers to, and finally we can simultaneously print messages to different targets.
Using bitwise operators with Actionscript to create arguments flags
Feb 8th
Among all books I bought (including Java books), I haven’t one which explain in depth and in a clear manner what bitwise operators are and how to use them. Almost all books has at least a page about the argument but none is able to give an exhaustive explanation. So, after searching the net, I found an extreme useful article by Joseph Farrell on gamedev.net (direct link: http://www.gamedev.net/reference/articles/article1563.asp), which explains bitwise operators in C starting from an introduction to Numbers and number system. The article is valid to Actionscript, Java and other languages too. I started to try to understand bitwise operators, after looked to Flex’s Alert class, which can accept several options (different buttons) as an unique argument (flags). This can be accomplished by using the bitwise OR operator | (a pipe), which “joins” together different constants:
Learning design patterns with Actionscript 3: episode 1 – Singleton pattern
Dec 28th
In these Christmas holidays I bought some new books, among them I purchased “Actionscript 3 design patterns” (written by William Sanders and Chandima Cumaranatunge) and I’m actually studying this one. I never faced before the world of design patterns (which is, for those that never heard about, a way to write code and solve problems by implementing tested strategies that will guarantee flexibility and extensibility), or better I knew what a design pattern is, but I’m trying to learn to use them for the first time.
Unfortunately the first thing I learned about implementing design patterns in Actionscript 3 is that for some stuff we have to use workarounds, because actually as3 doesn’t provides 2 little useful things: abstract classes (on which most of the patterns are based) and not public constructor (in Java we can declare a class constructor as private, in as3 we must declare it as public), anyway with some little efforts, we can do everything :-)
Adobe Flex 3 – Training from the Source… a new book to read :)
Nov 14th
Directly from Adobe’s Canadian headquarter and with the amazing efficiency of FedEx shipping (2 days only from Canada to Italy!), this morning I’ve received a new interesting and fresh book to read: “Adobe Flex 3 – Training from the source”… yes it talks about Flex 3, Actionscript and RIA and is part of an official books series from Adobe.
I would like to thanks Mike Potter, for the gift. I’ve appreciated it very much, and I hope to enter in the active Actionscript/Flex community as soon as possible.
Playing with Google maps API – Part one
Nov 14th
Ok, as announced in the previous post, let’s start to analyze how to work with Google maps (Javascript) API.
Preface: while I was writing I have been a little too verbose, so I won’t respect the previously declared steps, but I will add/modify them while posting.
Playing with Google maps API
Nov 13th
In my spare time, these days I’m looking at Google maps (Javascript) API, because relatively soon, I will have to realize a web site in which include a custom and interactive map.
In detail the site will be the official web page of an Italian bikers group, which will attempt to enter in the World Records Guinness as the largest bike aggregation of the same model (and I’ll be one of those crazy men! :-)))
The user will be able to subscribe to the event indicating his city and some other details.
And is here that the interactive map comes into play! It will shows the Italian map sprinkled by colored labels anchored to the main cities and indicating the total of subscribers in that city.
The label’s color will vary due to that number (green = few bikers, yellow = so so, red = many bikers).
I’m learning Actionscript 3… and I like it!
Nov 10th
After some tests with the Adobe AIR SDK, I’ve discovered the huge limits of developing in HTML + Javascript (of course I’m speaking about a desktop application perspective). So I’ve took a look around and I’ve realized that what I need for AIR (and not only) is Actionscript! It is infinitely stronger, flexible and better structured than Javascript, and with the 3.0 version is a true object oriented programming language. From my point of view it can be considered a middle way between Java and Javascript. In fact it has the OOP benefits as polymorphism, hineritance, interfaces, typed parameters and so on like Java, plus the flexibility of the coding style like Javascript, ie I can use JSON sintax and I’m free to code in “strongly tiped” way or not.
At the moment I’m studing the excellent book “Essential Actionscript 3.0″ and I’m already quite comfortable with the new language. The next book I’m going to buy are:
- Actionscript 3 design patterns
- Actionscript 3 game programming university
- Foundation Actionscript 3 animations: Making Things Move!
- Programming Flex 3 – The Comprehensive Guide to Creating Rich Internet Applications with Adobe Flex
So… like AC/DC say: “It’s a long way to the top if you want rock N roll” :-)
Recent comments