Posted by: Nick Jamil | July 25, 2009

A Shropshire Lad

cherry_snow A Shropshire Lad II

Loveliest of trees, the cherry now
Is hung with bloom along the bough,
And stands about the woodland ride
Wearing white for Eastertide.

Now, of my threescore years and ten,
Twenty will not come again,
And take from seventy springs a score,
It only leaves me fifty more.

And since to look at things in bloom
Fifty springs are little room,
About the woodlands I will go
To see the cherry hung with snow.

—A. E. Housman (1859 – 1936)

Posted by: Nick Jamil | May 6, 2009

Definitions

Defining terms is something that happens all the time. Whether it’s in a formal setting such as a university classroom in which a professor defines new terms formally, or when we’re with our friends and they ask us the meaning of a particular word while discussing… a book, say.

But the way in which we define something is not entirely enlightened; we tend to give synonyms. This is effective, but perhaps not the correct way to give a definition. What happens when, for example, there is no suitable synonym? And those that due render effective definitions don’t often understand the principles behind what they are doing.

So there is, in fact, a formal method and mechanism for formulating definitions. The basic stencil for a definition is this: “An A is a B which X, Y, Z”, where A is what we’re defining, B is the genus to which it belongs, and X, Y, Z, etc are differentia (sic.) that distinguish A from other entities in the genus B.

For example, let’s try to define the word “bed”. Bed belongs to the genus Furniture. Of course, it also belongs to the genus, Thing, Item, Object, Household Item, and any number of categories. But the most appropriate category is the most specific one that is widely accepted and understood. Next we differentiate Bed from other members of the genus Furniture. So a bed would then be a piece of furniture which is specifically designed for sleeping. We could have chosen other methods of differentiating bed, but the method of differentiation should be such that the fewest number of clauses needs to be used. Had we used the bed’s attribute of having pillows, this would not be enough since other pieces of furniture also typically  have pillows, and we would have been forced to do further clarification. So a bed is a piece of furniture designed specifically for sleep.

Another example: let’s define “human”. A human is many things; an animal, a mammal, a living thing, a solid object, etc. Animal, however, is the most specific genus without being too specific so as to require definition of the genus itself. Saying Mammal would have been going too far because Animal is close enough. Now there are many animals. What makes humans human? We could say that humans are animals that laugh. But then laughter is not intrinsic to humans. And if we said an animal that sneezes, then we would need other clauses as well since other animals also sneeze. A correct choice would be to say that humans are animals that are rational – humans are rational animals.

Posted by: Nick Jamil | May 6, 2009

Aspect Oriented Programming

Aspect Oriented Programming (AOP) is an imperative/procedural programming paradigm like OOP or Functional. It differs from other procedural paradigms in that its main concern is the functionality needed across different layers of an application architecture.

For example, logging is a service that is required by all layers of an application and the code behind this service is pretty much the same despite the client using it. So whether it’s the database that’s logging some information, the presentation layer, the business logic, the code will probably be very similar. Despite the differences in the layers of an application, there exist these cross-cutting concerns. Other concerns, besides logging, may include things like security, error handling, etc.

AOP and other paradigms are not mutually exclusive; you can have software that uses both AOP and OOP, for example. Where OOP modularizes the functionality of the application and divides it into tiers, AOP modularizes the cross-cutting concerns and divides it into services. So there might be a service for security which can be invoked by any layer of the application. Think of an n-tiered  application with its different layers; AOP would take this and do a projection on the security issues, or a projection on the logging issues, and isolate those… modularize those.

In a regular system, security might be scattered across the entire application. If you need to change some security logic, you’ll have to do it everywhere. With an AOP enlightened system, however, security would be a module/service. If you need to make a change, just change the service and that’s it. Plus you don’t want code that deals with security to be embedded in your business logic; it just gets in the way. AOP allows you to deal with it separately.

Some Terms

  • cross-cutting concerns: concepts like security and logging that are common to otherwise unrelated parts of a system
  • advice: the code to be applied for the cross-cutting concerns;  e.g. the code used for logging
  • join-point or pointcut: a place in the code where the advice needs to be applied; e.g. logging needs to happen after this call to the DB
  • aspect: the advice and the places it will be applied (the pointcuts) are together called the aspect

See: http://en.wikipedia.org/wiki/Aspect_oriented_programming.

Posted by: Nick Jamil | April 30, 2009

Poetry

So now I’m only waiting for one magazine to respond to my poetry submissions. And I’m quite sure that it’ll fall through (i.e. not be accepted). Several reasons might be at play:

  • I write classical English poetry, not modern. Not too many of the magazines which I’ve submitted to concentrate on classical English verse.
  • My poetry writing days are in their infancy
  • I read a lot of poetry to get an idea of how it works and what is good and what isn’t. However, I do limit myself so as not to be over-influenced in my style; I want to be somewhat unique.
  • My better poems are the more meaningful ones, but they’re private.
  • Maybe my poetry is too clandestine; it means something to me but not much to anyone else.
  • others? I just suck? lol

Here’s a sample poem… what do you think? It’s called A Dancer’s Figurine and it describes a person that makes you happy no matter how unhappy you feel. The person is compared to a fole and a fawn and some of their physical features are described – blond and outstretched hair, attractive teeth, etc.

From the grief of a trying toll
caused by a callous clutch
when it’s a trifle much
to safety of my buoying foal

My woe is muffled by the best
incisors smiling on
my precious little fawn
that make you distinct from the rest

A gorgeous head of gold serene
that stretches to and out
like a dart to its clout
and like a dancer’s figurine


Posted by: Nick Jamil | April 26, 2009

C# Tidbits

I’m going to try to populate this post with tid-bits as I learn more about C# and the .NET BCL.

  • string is an alias for String
  • string.Empty is preferable in place of “”
  • const is equivalent ot Java’s final
  • C# uses type-inference: var s = “a string”
  • bool is equivalent to Java’s boolean
  • strings are stored using UTF-16 encoding
  • C# also has a StringBuffer class with exactly the same purpose as in Java
  • C# supports structs; they can contain much of what a class can contain
  • primitives also inherit from System.Object; hence you can say 5.ToString()
  • the keywords out and ref cause a pass-by-reference
    class OutExample {
        static void Method(out int i) {
            i = 44;
        }
        static void Main() {
            int value;
            Method(out value);
            // value is now 44
        }
    }
  •  ref requires the variable to be initialized already
  • synchronization is realized using the lock-block
  • indexers (i.e. dereferencer overriding)
    class SampleCollection<T> {   

        // Declare an array to store the data elements.
        private T[] arr = new T[100];
    
        // Define the indexer, which will allow client code to use [] notation on the class instance itself. (See line 2 of code in Main below.)
        public T this[int i] {
            get { return arr[i]; }
            set { arr[i] = value; }
        }
    }
    
    // This class shows how client code uses the indexer.
    class Program {
        static void Main(string[] args) {
            // Declare an instance of the SampleCollection type.
            SampleCollection<string> stringCollection = new SampleCollection<string>();
    
            // Use [] notation on the type.
            stringCollection[0] = "Hello, World";
            System.Console.WriteLine(stringCollection[0]);
        }
    
  • Methods can be passed around as first class functions using delegates
    public delegate void Del(string message);
    // assign a function with the same signature as the delegate to Del

    public void MethodWithCallback(int param1, int param2, Del callback) {
    callback("The number is: " + (param1 + param2).ToString());

  • namespace block encapsulates classes and acts like the Java package keyword
  • C#-docs are done using XML tags
  • classes go in namespaces go in modules go in assemblies (which are either .exe or .dll files)
  • introspection tools are in the System library
  • extend is achieved by “:”. public class A : B { … }
  • destructors are part of the language. ~MyClass() { … }
  • performance
    • boxing/unboxing is expensive
    • use System.Text.StringBuffer for String operations
    • destructors are expensive
    • don’t unnecessarily use wide data types
    • reflection is slow
    • allocate memory conservatively (e.g. avoid String.Split on large strings)
    • too many pointers spells trouble for the GC and results in internal fragmentation
    • exception throwing is expensive
    • calling a function many times for each element of (for exmaple) an array is bad; create a function to handle collections (e.g. use AddRange for collections)
    • if data is very simple, use structs instead of classes because they’re continguously stored
    • use pools for connections, free space, etc
    • cache
Posted by: Nick Jamil | April 26, 2009

C#

Inception 2001
Proprietor Microsoft
Paradigm Multiple but mainly imperative with features of functional
Latest Release 3.0
Closest to Java

 

Characteristics (similar to Java)

  • strongly typed
  • single inheritance
  • automated memory management (including GC)
  • attention to distributed applications, portability, and internationalization
  • pointers (as in C) can be used in unsafe blocks
  • many compilers use JIT compilation
  • supports auto-boxing
  • implements a Common Type System where even primitives inherit from System.Object

 

Differences from Java

  • some keyword differences like using instead of import and foreach (string s in my_string) instead of for (String s : myString), etc
  • partial classes; implementation spread across classes with the same name for code auto-generation purposes and modularization
    public partial class MyClass { ... }
  • difference in parameterized type; the parametric polymorphism is cross-language
  • generators
    yield return X;    

    public IEnumerable GetEven(IEnumerable numbers) {
         foreach (int i in numbers) {
              if (i % 2 == 0) yield return i;
         }
    }

  • static classes are ones that cannot be instantiated or inherited from; contain only static members
  • member properties
    string status = string.Empty;
    public string Status {
         get           { return status; }
         protected set { status = value; }
    }
  • nullable vs. non-nullable types (even for primitives) for 1-1 correspondence with SQL data types
    int? i = null;
  • ?? is the null-coalescing operator; it returns the left argument if not null, the right otherwise
    return o ?? new Object();
  • LINQ is a SQL-like internal query language for operation on collections (as well as XML documents, etc)
    int[] array = {1, 5, 2, 10, 7};
    // Select squares of all odd numbers in the array sorted in descending order
    IEnumerable query = from x in array
                        where x % 2 == 1
                        orderby x descending
                        select x * x;
    // Result: 49, 25, 1
  • fast member initialization
    Customer c = new Customer(); c.Name = "James";
    Customer c = new Customer { Name="James" };
  • dynamic member assignment
    public static class StringExtensions {
         public static string Left(this string s, int n) {
              return s.Substring(0, n);
         }
    }
    string s = "foo";
    s.Left(3);
Posted by: Nick Jamil | April 26, 2009

The .NET Framework

Purpose A standard software framework for Windows-based applications
Proprietor Microsoft
Platforms Windows 98 and up
Latest Release 3.5 SP1
Components
  • Common Language Runtime (CLR): the runtime environment that handles things like memory management, garbage collection, and exception throwing
  • Libraries

 

Principles

  • language independence as provided by the CLR (like Java’s JRE)
  • the base class library (BCL) common across all languages
  • security
  • platform independence / portability

Notes & Terms

  • CLR is Microsoft’s implementation of the CLI (Common Language Infrastructure)
  • .NET assemblies is the CIL (Common Intermediate Language) like Java’s bite-code
  • CLR uses mark-and-sweep garbage collection, it is generational, and it runs only when memory is tight
  • the garbage collector pauses execution when running
Posted by: Nick Jamil | April 26, 2009

What’s Up?

I’ve been far too busy to continue posting on my blog; it’s been about a month and a half since my last post. The thing is, the technology news as seen on places like Slashdot is getting to be too much to summarize and I can’t muster the energy anymore. And besides, not many people read my blog anyways, lol.

So what’s happened over the past two months? Well school is almost over. I have an exam for csc443 – Database Technologies on May the 5th and that’ll be it; I’ll be graduating with an Hon. B.Sc. with a specialist in Software Engineering and a major in Near and Middle Eastern Civilizations, probably with a cumulative GPA of 3.3 (can’t change much now) and a language citation (for advanced study of the Arabic language).

There’s a high probability that I’ll be starting work on May 11. In preparation for that, I’ve been delving into the .NET framework and C#; I’ll post my summaries about the two shortly.

Most of the poems that I submitted to various magazines have been rejected. Although slightly disappointing. it’s not much of a surprise. I am still, however, waiting on two magazines.

I will be continuing my pursuit of Arabic scholarship with my old instructor. We will be starting soon – probably on Thursday evenings or something via Skype – and we’ll start with a book on Arabic rhetoric. Speaking of which, we’ve completed about 25 tutorials on LearnArabicOnline and I’m now working on making sure they are uniform and I’m adding internal links. It’s soon to become an authoritative site on the classical language… it’s so weird; my tutorials as authoritative works?

Stay tuned. In the meantime, here’s a hilarious video from SNL (Saturday Night Live) that I just can’t stop listening to. It’s obviously a parody of rap music… hilarious! Disclaimer: lots of coarse language and not recommended for my Muslim friends who read my blog.

Posted by: Nick Jamil | March 17, 2009

Little and Large

Researchers uncover the fossils of an enormous sea creature that lived about 1.5 million years ago and measured around 15 meters in length.

See http://blogs.nature.com/news/thegreatbeyond/2009/03/little_and_large.html.

Posted by: Nick Jamil | March 11, 2009

Inundated

I find, like many of my colleagues, coworkers, and professors, that the amount of bootstrapping that I do every morning before even considering my work is phenomenal. It’s become an intuitive reflex to open up Slashdot, ZDNet, BoingBoing, TechCrunch, DamnInteresting, The Great Beyond, IT Facts, The Star, among many others, after having turned on my computer and combed my hair. What ends up happening is that I waste away at least an hour reading these news blogs and my Golden Hours often slip through the cracks, leaving me doing 20% of my work using 80% of the rest of my day.

Read More…

Older Posts »

Categories