Is it too late to compete?

This question just came to my mind the moment I heard about the first beta release of an Arabic programming language called “kalimat” (words, Arabic: كلمات).

Is it to late too compete with .Net or Java (or possibly other frameworks/IDEs)? & if not, isn’t it a little bit late for Arabic?!

On the one hand, an Arabic programming language would be somewhat useful, specially if they decided to teach Egyptian students the basics of programming in public schools (teaching kids programming basics is the main purpose of this language, as announced). It also might find some good environment to grow in  Arabic speaking countries, from a business point of view.

But on the other hand, It’s unlikely to happen that Arabic programming languages (in general) would go further; i.e., to be embraced by non-Arabic speaking developers. It’s simple: we know English, they don’t know Arabic. In addition to being convenient to what they have & the continual rapid upgrade of existing frameworks/IDEs.

Personally, I don’t prefer Arabic & I don’t see it coming that I’ll develop in Arabic one day. I’m might try it though.

Let’s keep that aside anyway, I’ll keep being neutral.. It’s good to be neutral, you just wait & see!

BTranslator

BTranslator is a WPF application that translates text using Bing translator via Bing API 2.0. Bing API provides translation (as well as other services) using 3 data exchange protocols: JSON, Xml & SOAP.

BTranslator let’s the user chooses between the three protocols.

BTranslatorLib consists of three classes JSONTranslator, XmlTranslator & SOAPTranslator. They all implement IProtocol interface which has one function called Translate.

Translate takes 3 parameters: Text to translate, from language & to language and then uses these parameters according to the protocol’s structure.

Download BTranslator – 694 KB

*Further explanation might follow

Three very basic sorting algorithms

In this post, I’m going to briefly explain three very basic sorting algorithms: Bubble sort, Selection sort & Insertion sort.

Bubble Sort:

Assume that we have an array of integers that we want to sort: 4,5,1,2,7,8

What would be the most basic thought that would cross your mind? Well, simply to take each pair & see if they are in a wrong order & then re-arrange them.

Why “bubble”?

As we said we exchange each two numbers if they have an incorrect order, so whoever invented this algorithm saw this exchange as some water bubbles that float to change their position!

Let’s do it:

4,5,1,2,7,8–> correct order no change

4,5,1,2,7,8 –> 4,1,5,2,7,8

4,1,5,2,7,8 –>4,1,2,5,7,8

4,1,5,2,7,8–> correct order no change

4,1,5,2,7,8 –> correct order no change

It’s clear that we’re not done though we’ve iterated on the whole set. So we need to loop again & not just once but till n-1 .. which is the count of the number -1.

Again:

4,1,5,2,7,8 –> 1,4,5,2,7,8

1,4,5,2,7,8 –> correct order no change

1,4,5,2,7,8 –> 1,4,2,5,7,8

1,4,2,5,7,8–> correct order no change

1,4,2,5,7,8 –> correct order no change

Third iteration:

1,4,2,5,7,8 –> correct order no change

1,4,2,5,7,8 –> 1,2,4,5,7,8

and we’re done! .. yet there’s one problem .. Bubble sort never knows when it’s done .. so it will just continue iterating until n-1 with each time comparing adjacent numbers. This lead to the introduction of the Modified Bubble Sort algorithm which checks every time if the position of any number has changed, if not it quits.

The complexity of this algorithm is O(n^2). For those who don’t know this means that it needs 2 for loops each of a stopping condition (< length of numbers) to finish sorting at the worst case. Try sorting the numbers when they’re totally reversed 8,7,5,4,2,1 & count the number of steps.

Code (unmodified):


 

Selection Sort:

This algorithm simply selects the smallest number in the unsorted array & place it in the first place (index =0), then selects the second smallest number & place it in the second place (index =1) .. etc. I guess you concluded why it’s called selection!

Example:

Let’s stick with the same set of numbers:

We have two cursors, the first one is set to the index of the first element (index = 0, we initially assume that it’s the min value) & the second one selects the min value & swaps them

4,1,5,2,7,8 –> 1,4,5,2,7,8

then the first cursor moves to index =1 and assumes that its the min then does the same with the remaining numbers from (4,5,2,7,8)..

<1,4,5,2,7,8 –> 1,2,5,4,7,8

1,2,5,4,7,8 –> 1,2,4,5,7,8 .. Done!

but it will just continue as the bubble sort ..

Code:

Insertion Sort:

This is the most realistic search you would ever meet. It just analogues the way you might sort some cards. Assume that we have 4 cards that are randomly sorted: 7,3,5,9 & that we have a table that we would like to put them sorted on (left to right).

Trace:

You hold the first card: 7 .. well it’s the smallest so far .. so we’ll put it on the left side. The second card is 3 .. OK smaller than 7 .. move 7 to the right and put 3 in the left most place.

Numbers so far: 3,7,5,9

Next, 5 .. smaller than 7, move 7 to the right & put 5 in it’s place .. continue, 5 is not smaller than 3 .. so we’re not exchanging them [3,5,7,9]. Same will happen with 9 but no change would happen .. although it will check anyway.

Implementation:

Now we need to loops .. one to that moves element by element in the array, and the other to compare the element chosen by the first loop to the element next to it. if the element selected by the first loop is smaller than the element selected by the second loop .. we shift the elements to the right to make room for the element selected from the second loop.

Code:

*This post is inspired by: Data Structure & Algorithms using C#, Michael McMillan

Simple web browser using C++/CLI

Lately I became interested in C++ so much .. I started reading from where we stopped at college and also started learning some related technologies like C++/CLI & MFC which are used to develop windows applications using C++.

Anyway, this one of the simplest applications that you would do if you’re a C++/CLI beginner ( may be with some C# windows programming background)

Open your Visual Studio -> New Project -> Visual C++ -> Windows Forms Application

This looks pretty much like C#, the same controls on the toolbox & the same initial form .. even if you pressed Right Click -> View Code, you’ll find the same stuff that you find in C# forms except that the designer code & the code you’re going to write are on the same file.

Now go to the toolbox & and grab a Menu Strip then add 3 buttons & a TextBox inside it The user should enter the Url in the TextBox .. and then press Go To .. We’ll also have Forward & Back buttons.

Then add a web browser control under the Menu Strip .. It should look something like this:

Now let’s add some functionality for this .. Double Click on the Go To button and inside the click event handler write:

webBrowser1->Navigate(txtUrl->Text);

The Navigate function takes the text written in the textbox & ‘navigates’ to it.

Pause: Selection Operator (->):

>Now you might want to ask about the difference between the selection operator (->) & the dot (.) which is also used to access public members/functions of a class.

Well, it’s simple .. assume that we have class Student & that we created these instances:

Student stud

Student *studPtr = &stud;

Student &studRef = stud;

So we have stud (an object of Student), studPtr (a pointer to a Student object)

& studRef (a reference to a Student object)..

Assume further that Student has a Name which is a public member..

So if you want to access Name in the three cases this would be:

stud.Name = “name1″;

studPtr->Name = “name2″;

studRef.Name = “name3″;

That is, when you’re accessing public class members/functions of pointers to objects you use -> while a dot (.) is used if you’re dealing with an instance or a reference to an object of a class .. easy!

Back to our browser:

Do the same double click with the Forward/Backward buttons to create their event handlers ..

We’ll just call the GoBack() & GoForwad() functions found inside the webBrowser1

Browse!

Now let’s run and start some browsing ..

VS 2010: New IDE features 2

More Features:

  • Reference Highlighting:

This a very helpful feature, If you click on any Variable/Function VS 2010 editor will find all other occurences of this Variable/Function & highlight it:

 

Same with Methods (Functions):

 

You can disable this feature using: Tools -> Options -> Text Editor -> C#-> Advanced.  Uncheck “Highlight references to symbol under cursor”.

  • Zooming:

It’s now easier to Zoom In/Out .. just use your CTRL + Mouse scroll.

  • Column Selection:

Hold ALT & try to select some colums (Vertically) instead of selecting statements (Horizontally)!

More to come..

VS 2010: New IDE features

As I mentioned before, I’ve been playing around with Visual Studio 2010 since the Beta 2 version .. here are some of the new IDE features that makes your coding experience way much intresting!

  •  The look:

Well, VS 2010 is now based on directX instead of GDI .. so things are much smoother & faster .. here’s how the start page looks:

It’s reacher now containing links to toturials, sample projects, news, updates, community events .. etc .. all categorized by Type (Windows, Web .. etc)

  • More on Start:

You’ll also note that the Recent Projects section has been changes a little bit, now you can pin you’re important projects to keep them forever.

In addition to that, If you’re using Windows 7 .. you can now pin your project solution to the start bar:

  • Generate From Usage:

OK, let’s make a new console project let’s call it “StudentSimpleApp” .. assume that we want to add a new Student class to our application .. you actually don’t have to do it the old way .. you know –> Add  –> Class.cs ..  No not really!

I’ll just start typing Student:

The editor is telling me that something is wrong .. so I’ll press ctrl + “.” … “Generate class for Student”!

Here’s it, created & added to the Solution Explorer!

  • More on Generate From Usage:

You can also start adding some Fields, Properties  & Functions without even opening the Student.cs!

Even constructors can be added the same way along with whatever parameters you want them to take! (Try it yourself)

Okay, let’s check  class Student:

 

Great, isn’t it?

More features soon, stay tuned!

Doing your thing(s)

 A sinful belief is out whenever a young kid starts going to school: Those of high marks are intelligent, others are dorks! .. so you should study hard and get high marks!

After deep thinking I came to a belief that there are several types of intelligence, one can have just one, or many..

Here are some types of intelligent people whom are not necessarily of high marks in their classes:

  • The Physical/Athlete: Someone with great physical stamina, when you give him something to ‘DO’ .. you just get astonished on how he didn’t collapse like his colleagues, he probably knew how to put his energy into full use. He’s for sure best for physical work and sports
  • The Researcher/Studier: He’s never enough with school and university. You can never get him to the market. He’s best when left with books and researches.
  • The Speaker: Choosing the right words, ability to persuade and convince .. a great sign of uniqueness.
  • The Logical guy: Those of good skills of interpretation and analysis, most likely to be philosophers.
  • The Planner/Organizer: While everybody is confused and tensioned, he keeps looking from up there were nobody has or will reach. Best as a Manager/Leader.
  • The Social guy:  Dealing with people is an art, knowing when to talk and when to hush, when to smile or act in certain way is definitely a gift.
  • The Mathematician: The guy who can divide a 1872 by square root(9782.176) then powers to 7.3 and multiplies by 3276.2238 .. while you’re still trying to remember what would 8*7 be coz you didn’t memorize “Gadwal el darb” back in fourth primary! .. it’s 56 anyway!
  • The Musician: Making others feel thankful for having ears or getting some words to dance  .. I’ve never been wondering about anything more than that!
  • The Drawer: Lines, colors & imagination .. a total brilliance package.
  • The Memory guy: A look is enough to get everything inside the store.

A wish, a fact & a tip:

A wish: I wish we really change the way we judge the poor kids  intelligence here in Egypt. It’s never about getting high marks, not with Egyptian education system at least!!

A fact: Everybody is intelligent in their own way.

A tip: Find your thing(s) and do it.. do it vigorously!

F# for FCIS Juniors

Yesterday, I decided to install Visual Studio 2010 Beta 2 and start diving into its new features. This seems to be very late, it’s been out since May!       

Anyway, one of the things that attracted me most, besides the great IntelliSense and the WPF based UI, was F#. F# is a new functional language introduced by Microsoft …. so what are really functional languages?   

The first time I heard about the term “functional language” was in a compiler section by Dr.M.Saber ..        

Functional languages provides means to write code that looks like mathematical functions, this is way different from OOP of course. The most interesting part is that the first functional language “IPL”was invented in 1955, yet when OOP started to show up in 1970s .. it wiped away FL, at least commercially!   

Back to F# .. these are some code samples for the newly born language:       

Simple assignment:       

let A= 1
let B = 2
let C= A + B
 
Once a value is assigned to an identifier in FLs, it can’t be changed .. pretty easy and Math-like!
Now let’s get things more compilcated ..   

Working with Functions [Think Math please]:     

 let f x = 2*x*x – 5*x + 3 

 F is the name of the function – x is the parameter, so for using this function we can simply write ..   

 let result = f (C + 4) 

 Even bizarre recursion looks simpler .. 

let rec factorial n = if n=0 then 1 else n * factorial (n-1) 

Well it still looks creepy.. yet takes less time and effort to get! 

One of the great advantages of functional languages is how in short sentences you can write a powerful application. Some FL supporters declare that programs in FL  are 90% shorter!!   

My believe is that the greatest advantage of all is how mathematical FLs look which would be a great chance to get those of mathematical background into code, instead of suddenly shocking them with the fact that under some cirumstances x might be equals to x+y !! 

*Code samples are taken from Tutorial project found on VS 2010 Beta 2 version.

Learning Xna

Yesterday, We made our first rehearsal for the Xna workshop we’re preparing to present in COMPASS’10 … hmm .. I think things went well..

I can’t really remember how it started with Xna and who exactly told me about it .. nah .. this is out of my memory range! .. though I think it was around the end of the second semester in third year .. yeah probably that’s when I started to read about it ..

One of the main reasons I got into FCIS was game development .. this one question:” How do they make these games?”  kept flowing all the way .. this is also why I’ve chosen SC ;)

I don’t mind working with OpenGl or DirectX at all .. even though OpenGl was disastrous last year! .. It’s just that I nearly taught myself everything about Xna and that was completely new to me .. I’ve been interested in enhancing my technical skills!!

Anyway .. We still have too much work to do preparing the workshop .. I hope things go right!

Being a senior ..

My Second week officially as a senior student has just started .. honestly, I can’t get in the mood of being a senior .. no .. not yet!!

I really can’t find a reason .. may be the change ( Genedey all day!) .. even worse, most of the time inside this one single SC lab!

May be the way SC dept. looks too small when it comes to numbers .. 29 members! ..
In addition to being away from some friends!

Anyway .. I’ll keep being optimistic .. there are some interesting stuff to do ..

  • Being a Microsoft Student Partner
  • Workshop Moderator COMPASS’10
  • Graduation Project
  • SC ..  yeah .. some subjects seem to be encouraging ;)

 Let’s wait and see!

Follow

Get every new post delivered to your Inbox.