Made to Order Software Corporation Logo

expression

Don't Repeat Yourself When Writing Software

Nature tends to repeat itself, or reproduce with similar structure, but code should not.

For a very long time now, we have been using languages that support having functions that one can call. That was not always the case, although even really old versions of BASIC had a GOSUB instruction, which it had no concept of local variables so it was rather difficult to use safely.

Functions allow you to avoid repetition. You write a small snippet of code (or maybe not that small) within a function and then you call that function to reuse that snippet over and over again. Good programmers tend to do that even with one liners. However, many others often think: well, it's just one line, why don't I return copy & paste that wherever I need it, it's going to be faster.

CSS3 media queries

CSS is improving with the introduction of CSS3.

Contrary to the previous version, CSS3 supports selections that are very advanced, offering capabilities close to what you could write in JavaScript.

Today I wanted to talk about the Media Queries because that can be used to very much optimize the list of links used to load your CSS data.

In HTML, you can use a <link ...> to add a CSS file to your page.

<link rel="stylesheet" type="text/css" href="style.css" />

In this case, the file style.css will always be loaded, whatever the media being used.

Wait For Frame (dynamic)

SWF Action
Action Category: 
Movie
Action Details: 
(dynamic)
Action Identifier: 
141
Action Structure: 
unsigned char    f_skip;
Action Length: 
1 byte(s)
Action Stack: 
pop 1 (a)
Action Operation: 
a1 := pop();
if(_root.get_frame() >= a1) {
  // execute f_skip bytes of instructions
  ...
}
else {
  // ignore f_skip bytes of instructions
  pc += f_skip;
}
Action Flash Version: 
4

Pop a value or a string used as the frame number or name to wait for. The frame can be specified as with the Goto Expression. If the frame was not reached yet, skip the following f_skip actions.

WARNING

Goto Label

SWF Action
Action Category: 
Movie
Action Details: 
0
Action Identifier: 
140
Action Structure: 
string   f_label;
Action Length: 
-1 byte(s)
Action Stack: 
n.a.
Action Operation: 
goto(f_label);
Action Flash Version: 
3

Go to a named frame. Frames are given names with the use of the FrameLabel tag.

This action has a behavior similar to a Goto Expression with a string.

Goto Frame

SWF Action
Action Category: 
Movie
Action Details: 
0
Action Identifier: 
129
Action Structure: 
unsigned short   f_frame_no;
Action Length: 
2 byte(s)
Action Stack: 
n.a.
Action Operation: 
goto(f_frame_no);
Action Flash Version: 
1

The playback continues at the specified frame. Frame numbers start at 0 and go up to to total number of frames - 1.

A frame appears at each new Show Frame tag.

For a goto frame with a dynamic frame number, use the Goto Expression action instead.

Goto Expression

SWF Action
Action Category: 
Movie
Action Details: 
0
Action Identifier: 
159
Action Structure: 
unsigned char    f_play;
Action Length: 
1 byte(s)
Action Stack: 
pop 1 (a)
Action Operation: 
a1 := pop();
goto(a1);
Action Flash Version: 
4

Pop a value or a string and jump to that frame. Numerical frame numbers start at 0 and go up to the number of frames - 1. When a string is specified, it can include a path to a sprite as in:

/Test:55

When f_play is ON (1), it wakes up that sprite (movie, thread). Otherwise, the frame is shown in stop mode (it does not go past the Show Frame tag.) This action can be used to playback a sprite from another given a set of events.

Get Target

SWF Action
Action Category: 
Movie
Action Details: 
0
Action Identifier: 
69
Action Structure: 
<n.a.>
Action Length: 
0 byte(s)
Action Stack: 
pop 1 (o), push 1 (s)
Action Operation: 
o1 := pop();
r := target_of(o1);
push(r);
Action Flash Version: 
5

Pop an object, if it is a valid sprite (same as movie or thread), push it's path on the stack.

A sprite path can be used by different other actions such as the Goto Expression.

PostgreSQL and Drupal conflict

We have been running Drupal for some time now and we have noticed that it generates a very large amount of warnings in our log files.

The warning is in link with improperly formatted strings. PostgreSQL tries to follow the SQL specification to the letter and that means you cannot use the backslash character to escape special character sequences (such as \n for a newline character.)

I knew that in most cases the error was generated because of the function saving a full page or some other content in the cache. In that case, the system includes the characters: \012 and \015 (\n and \r.) That ...

The assert() macro in C/C++

 

This is a subject that comes back all the time in C/C++ boards.

Should you use assertions?

The answer is clearly yes. But the C/C++ assert() function is usually defined using a macro. Macros have several problems. The most common ones are: they offer no type checking, they do not warn you about weird side effects, they have a different syntax than the C/C++ language itself.

One good thing: for a fast program, the debug code used to check parameters, results, etc. is gone.

One really bad thing: if the expression in the macro has a side effect, the release program is different from ...