Windows 7 “Advertisment” : Surf the web or surf Hawaii

I haven’t laughed that much for a long time!

Microsoft, in an effort to convince the users to buy a PC (running Windows 7) over a Mac, launched the following advertisement where it compares several Macs with Windows 7 based PCs.

In principal, I agree with the concept; why paying so much money for a Mac? But:

  • Surf the web or surf Hawaii??? Using a Windows PC, aren’t you supposed to be able to surf the web also :-D? Maybe say “Surf the web, surf Hawaii, or both”!
  • They could use PCs with the same (or more similar) CPU with the respective Mac in order to be more convincing..

Anyway, Microsoft is fun.. and desperate (??). Do the math.

Netbeans 7.0 on Ubuntu Installation – OpenJDK problem

Installation

The installation process is simple:

  1. Download the version you want to install from here.
  2. Navigate to the folder were the .sh file was downloaded.
  3. Give executable permissions to the .sh file.
  4. Execute the installer (.sh) file either pretending sudo command (in order to install it in the default /usr/local/netbeans-7.0 location) or without (in order to install it in the /home/Username/netbeans-7.0/ location)
  5. Use the Graphical Installer to do the installation.

For example:

[~] $ cd ~/Desktop/                                                     # Step 2
[~/Desktop] $ ls -l netbeans-7.0-ml-cpp-linux.sh 
-rw-r--r-- 1 *** *** 45967360 2011-05-03 09:21 netbeans-7.0-ml-cpp-linux.sh
[~/Desktop] $ chmod +x netbeans-7.0-ml-cpp-linux.sh                     # Step 3
[~/Desktop] $ ls -l netbeans-7.0-ml-cpp-linux.sh 
-rwxr-xr-x 1 *** *** 45967360 2011-05-03 09:21 netbeans-7.0-ml-cpp-linux.sh
[~/Desktop] $ sudo ./netbeans-7.0-ml-cpp-linux.sh                       # Step 4
Configuring the installer...
Searching for JVM on the system...
Extracting installation data...
Running the installer wizard...

OpenJDK Problem

The problem with OpenJDK

Configuring the installer...
Searching for JVM on the system...
Extracting installation data...
Running the installer wizard...
null

while installing Netbeans 6.9.1 on Ubuntu is the same for Netbeans 7. Netbeans needs Sun JDK to work, otherwise even the installation wizard (GUI) does not appear.

Read more details about the problem and how to solve it in the post about Netbeans 6.9.1.

Introduction to Erlang : List Comprehension

This entry is part 13 of 16 in the series Introduction to Erlang

List Comprehension

Do you remember the lists:map/2 and lists:filter/2 functions from the previous post? If not, consult the Lists & lists Module post. lists:map(Function, List) returns a new list that results from List after applying the Function to each element. lists:filter(Predicate, List) returns a list that contains only the elements of List for which the call to Predicate returns true.

Both the aforementioned operations are commonly used, as well as their combination; map & filter (does it remind you map & reduce?). Erlang provides this combined functionality using the list comprehension construct.

Format

A list comprehension look like the following:

[Expression || Generators1, Guards1, Generators2, ...]
Generators

As their name suggests, generators create the data used in the filter-map operations. A generator has the Pattern <- Data format, where Data is a list or an expression that results to a list and Pattern is a pattern used to match with the elements of the list. This pattern can be used to disassembly elements. For example, two valid generators are I <- lists:seq(1, 10) and {X, Y} <- [{'A', 'Excellent'}, {'B', 'Good'}, {'C', 'Fair'}].

Expression

The expression specifies the elements of the result. For example, [I || I <- [1, 2, 3]] returns the input list element as is.

Guards

Guards are expressions that return either true or false, the same as the guards we have seen in the previous posts. They apply to the variables that are on the left of the guard and the ones that are accessible due to the scope where the comprehension runs. For example, I <- [1, 2, 3, 4], I rem 2 == 0 is a valid generator - guard combination (the result should be obvious; only the even numbers "pass" the guard's test).
Read the rest of this entry »

Introduction to Erlang : List & lists Module

This entry is part 12 of 16 in the series Introduction to Erlang

List

List is the the most important data type in Erlang, as in every (?) functional programming language. We have seen and used lists in almost every previous post. In this post, I will briefly present the “theory” of lists and then present the Erlang’s lists module and its most important functions.

Definition

A list can be recursively defined as the construct that

  • either is the empty list (denoted as [] in Erlang),
  • or is a cosntruct that its first element is a term (called head) and what remains if the head is removed is a list (called tail)

In Erlang a list of N elements has the [Element1, Element2, ..., ElementN] format (N is called the length of the list). So, [] is the empty list, [1], [{a}] are 1-element lists, [1, 2], [a, {b, c}] are 2-elements lists, etc. As we will see in a while, the format [Element1, Element2, ..., ElementN] is a shorthand for the [Element1 | [Element2 | ... | [ElementN | []] ... ] representation.
Read the rest of this entry »

Introduction to Erlang : BIFs & Predefined Modules

This entry is part 11 of 16 in the series Introduction to Erlang

Built-in Functions (BIFs)

Erlang’s Built-in Functions (shorthand BIFs) are commonly used functions that are intergrated into the Erlang’s VM for performance reasons. Most of them belong to the erlang module, but there are some in other modules, such as lists.

The BIFs can be separated to standard and non-standard. The standard ones are auto-imported; they can be called without the use of the module name prefix (remember the effect of the -import(...) directive). On the other hand, the non-standard ones have to be called following the normal module:function(...) convension. In the erlang module’s man pages (here) the distinction between standard and non-standard is visible by the lack or existence of the erlang (module’s name) prefix.

elrang

abs/1

Arithmetic absolut value of an integer or float.

erlang:append_element/2

Appends an element to a tuple.

apply/2|3

Calls the function passed as a parameter.

atom_to_list/1

Returns a string which corresponds to the text representation of Atom.
Read the rest of this entry »

Introduciton to Erlang : Recursion (2/2)

This entry is part 10 of 16 in the series Introduction to Erlang

Accumulators

In several cases, as with the mlists:length/1 example, the non-tail recursive function can be easily turned to a tail recursive one by using the notion of accumulator. An accumulator is an extra argument introduced to a function in order to aggregate the partial results of the function. It turns the “bottom-up” collection of the final result to “top-down”.

In order to add and initialize the accumulator argument one has to introduce an extra function definition.

tlr(...) ->
    tlr(..., Accumulator_initial_value).
 
% the clause that "breaks" the recursion and
% returns the result
tlr(..., Accumulator) -> 
    Accumulator;
tlr(..., Accumulator) ->
    ...,
    Accumulator_new_value = ...,
    ...,
    trl(..., Accumulator_new_value).

Notice that typically you would only export the tlr/1 function and the tlr/2 would remain for inner-module use and not visible to the module’s users.
Read the rest of this entry »

Introduction to Erlang : Recursion (1/2)

This entry is part 9 of 16 in the series Introduction to Erlang

Recursion

The definition of the word recursion is “(mathematics) an expression such that each term is generated by repeating a particular mathematical operation”, according to the WordNet. Recursion is one of the most powerful “tools” in a functional programming language and so it is for Erlang. Recursion can be used to apply divide and conquer techniques to problem solving, where a problem is broken to smaller subproblems, the subproblems are solved, and the results are “merged” to generate the final result.

Recursion happens when a function’s body definition includes a call to the function itself.

functionA(...) ->
    Body_before_recursion, % optional
    functionA(...),
    Body_after_recursion. % optional

Recursion is used instead of the conventional loop statements of other programming languages, such as while and for in C.
Read the rest of this entry »

Functional instead of Object Oriented Programming at CMU

Recently, Robert Harper, a Professor of Computer Science at Carnegie Mellon University (CMU) posted about the new introductory CS curriculum at CMU.

Two new courses has been introduced and one more is planned. The first two are about Functional and Imperative Programming respectively. The third one will be a course on Data Structures and Algorithms.

At the same time, Object-Oriented programming is removed from the introductory curriculum, because it is considered both anti-modular and anti-parallel, thus unsuitable for a CS curriculum.

The Standard ML programming language will be used for the Data Structures and Algorithms course. SML was also my first functional programming language while taking the Programming Languages I course during my Diploma. Although it is a “clean” and easy to go language, I would prefer a more inherently parallel language to be used instead. Erlang could be a good candidate!

I vote for this change :-). This shift “against” Object-Oriented programming is a natural one since Parallel Programming is a necessity in the Multi-core era.. An old joke (which is actually stolen from a joke about regular expressions) says:

You have to solve a problem. The problem has certain performance requirements. You decide to use Java and threads.. You have to solve two problems.