Articles Tagged 'Code'


Coding Guidelines

When no longer working alone for all developers comes time to find guidance in the writing of code. Protocols and standards that make it possible to "read" easily and intervene (more easily) in the code of others.
When we are working on a project more programmers, often of different languages, you must find a common form of writing, internal and external documentation standards in the code. In my work I am usually to interact with:

  • Objet-C, C / C + +
  • PHP
  • HTML
  • JavaScript
  • Actionscript
  • CSS

Continued ...

PhpStorm 2.0

PHP IDE dedicated to the development there are many, ranging from free to paid ones. For a long time I have used tools such as Eclipse or Aptana , coming to make use of specialized editors to HTML / JavaScript and - even - CSS. For a year now, however, I think I found a complete environment that finality, at least in my case, it solves all my problems: PhpStorm .

Continued ...

Very short trick: making invisible HTML comments

Comment HTML is a practice during the early stages of Web development, however the commented code remains visible on the page, even if it is ignored by the browser. By selecting "View Source" or "View Code" from our browser, we will be able to see it.

Continued ...

Xcode shortcut

Xcode is a really good development environment, nice and full of details that make writing efficient code and pleasant. Among these is the ease of auto-complete when typing, especially when writing applications for Apple iPhone, where the frameworks are many and remember syntax and nomenclature company by a few.

Continued ...

XCode: organize your code with the # pragma mark

XCode is a very powerful and versatile and provides the programmer with many useful features and simple to use. When writing complex code, or at least articulated, it becomes important to organize your code so you do not waste time searching functions spread in long lines of code. After commenting, the first and most important thing to do, the environment XCode provides guidelines (nice) to improve the usability and legginilità within the development. One of these is the directive #pragma mark that becomes very useful in organizing groups of the code and methods.

In the picture below you can see the code part of my project PragmaTest :

pragmamark-1

The top dropdown menu allows you to list all the methods of our class. Now if we insert our method over the directive #pragma mark which has a syntax:

1
# Pragma mark {label}

We get:

pragmamark-2

The first #pragma mark with a hyphen (-) inserts a separator line. The second is a text (label) to taste. You can add the following statement where you want, organizing the code as you see fit. You can enter more pragmatic lines, type:

1
2
3
4
5
6
# Pragma mark -
# Pragma mark / **
# Pragma mark * Using the pragma
# Pragma mark * on several lines of code
# Pragma mark * /
void ) mioMetodo { } - (Void) {} myMethod

Continued ...

iPhone Objective-C syntax equivalence

The syntax with square brackets in Objective-C is one of the reasons most frustration for those coming from other languages ​​(for objects). However, get used to it, you realize how readable the code becomes too with this mix of classical and more distinctly syntax Smalltalk. For example we see how the same procedure can be written in both syntax. Take the initialization of a UIAlertView :

1
2
3
4
5
6
7
8
[ [ UIAlertView alloc ] initWithTitle : @ "Titolo" UIAlertView MyAlert * = [[UIAlertView alloc] initWithTitle: @ "Title"
"Messaggio" message: @ "Message"
delegate: self
"Annulla" cancelButtonTitle: @ "Cancel"
"Ok" , nil ] ; otherButtonTitles: @ "OK", nil];
; myAlert.tag = 1;
; [MyAlert show];
; [MyAlert release];

The setting of the tag potavamo it even so:

1
2
3
4
5
6
7
8
[ [ UIAlertView alloc ] initWithTitle : @ "Titolo" UIAlertView MyAlert * = [[UIAlertView alloc] initWithTitle: @ "Title"
"Messaggio" message: @ "Message"
delegate: self
"Annulla" cancelButtonTitle: @ "Cancel"
"Ok" , nil ] ; otherButtonTitles: @ "OK", nil];
1 ] ; [MyAlert SETTING: 1];
; [MyAlert show];
; [MyAlert release];

Same thing in reading during the event:

1
2
3
4
5
void ) alertView : ( UIAlertView * ) alertView clickedButtonAtIndex : ( NSInteger ) buttonIndex { - (Void) alertView: (UIAlertView *) alertView clickedButtonAtIndex: (NSInteger) {buttonIndex
alertView.tag == 1 ) { // ... if (alertView.tag == 1) {/ / ...
/ / Or
alertView tag ] == 1 ) { // ... if ([alertView tag] == 1) {/ / ...
}

Note: Not all properties or methods have this dual syntax. In the case of ' UIAlertView we have this dual functionality. For other objects, or in other cases, however, only one of the two might work ... but do not ask why (depending on how the developers have defined the interface).

Continued ...

Very short snippet: Actionscript extend an array by the method shuffle ()

I had already talked about how to implement the method shuffle () in Javascript and Actionscript . I realized, tuttaavia, not pointing out that it is able to extend Actionscript, Javascript in the same way, its object Array :

Continued ...

Very short snippet: shuffle () in Javascript and Actionscript

In PHP there is a handy feature called shuffle() that allows you to mix an array (see Very short trick: take random elements from an array in PHP ). An excellent version of the javascript I found here . Slightly revised the code below:

Continued ...

WordPress: customize the navigation between the posts

WordPress offers many features to navigate through the various posts and pages forward and back. These are used within the themes, often in a completely interchangeable, although they contain some differences. This, in fact, create much confusion in the choice of the function to use. Here are some notes:

Continued ...

Very short snippet: Wordpress, separate the categories into two columns

Inspired by WordPress Hack # 2 - Separate the categories in the sidebar columns can be useful "break" in two columns list the categories of WordPress.

Continued ...