March 2008 - Posts

I was in the middle of downloading screencast from Channel9 of MSDN and also finishing my part 2 blog.

To my surprise, the 3G connection went so fast! Many thanks to my XL 3G for this connection:

image

Before this, I always complained to them about how slow it was.

But right after that, I test the real speed using intel bandwidth test:

image

 

It looks like I only have a quick surge of 3G speed. Well.. For this speed, it's still slower thean my ISDN connection at home. But, anyway, it's fun to test the real speed. Also, maybe I should sample more test.

I have tested it again many times, and this is what I got an average of 72kbps out of 5 times testing:

image

So, what I got is a quick surge of 3G speed. Has any of you experienced this phenomenon too?

Share this post: | | | |
Posted by eriawan | 4 comment(s)
Filed under: ,

Yeah. I know. It's quite noisy, either in INDC's mailing list, or in many web that says cool features in VS 2008.

But let me straighthen up first, why I choose LINQ first? It's because becoming hot buzzwords number one. And it can get many wrong views.

 


UPDATE:

27th March, 2008: fixing typos, code samples are now in C# 3.0 and VB 9.0, not just C# 3.0.


 

LINQ views and what comes in a single query of LINQ

Ah. Language INtegrated Query. Everyone has been becoming crowded and many shouting at me, "I know it! Of course I know!" But many don't know, it's not just a new essential features of VS 2008, but it's more like one of new features of .NET 3.5.

I also often heard many mumbles that said, "LINQ is the only way","LINQ is the newest concept from Microsoft's family of programming languages", blah, blah, blah, and many leads to almost false altruism.

It can be a sad fact for us but it's true, LINQ is not all that new! In "C Omega", or Cω, the notion that you can include SQL query such as Select is already available before C# 3.0. The name itself is new. Yes, the term LINQ is new, but the concept behind it it's not new. But why I say, not all? The concept of bringing Lambda expressions to LINQ queries are new. I'll try to explain it after this LINQ views.

LINQ it's not exclusive of .NET 3.5, though. Because it's simply a set of new language features capabilities that built into the fabric of C# 3.0 and VB 9.0 language specifications in terms of new keywords and new syntaxes. Most of all, it's simply a syntactic sugar, to ease all of us writing codes especially when dealing with SQL query language syntaxes. And don't forget one thing, .NET 3.5 is still .NET 2.0 lies beneath. So, .NET 3.5 was built on top of .NET 2.0 added with .NET 3.0. It's not exclusive, right?

Since LINQ is not exclusive of .NET 3.5, it's also implied that you can still can do your hard work in doing querying data. Still, you can do many things in ".NET 2.0 ways". But we, as software developers, tend to be more productive, and can be we're obligated to be always more productive and also more innovative in doing our core responsibilities, solving business problems and coding.

So, I strongly suggest that you use LINQ if you have Visual Studio 2008, and please upgrade to VS 2008 if you have 2005 since your new learning curve is not that new. Why? I'm not a strong opponent of using LINQ. In fact, I (again) strongly suggest you to use LINQ as appropriate and wisely for your development. It's helpful. It's not a must, but it eases our coding, and also promoting easier to read and then to code (can be the other way around).

Why? Because you'll get compile time checking and Intellisense in your query syntaxes! This means less error, more focus to the query logic. Also another why is, it's a way to compose pieces of arcane nested select queries, which can have many side effects. This concept comes from functional programming, and later I'll explain this after LINQ stuffs.

But be prepared to dive the concept behind LINQ uses first. You have to know it. I strongly suiggest you to learn it also. There are some facets of many programming paradigm "hidden" from us!

 

A quick LINQ to SQL

First, easier to code. Why? Let me give you a basic example of LINQ querying a LINQ to SQL (formerly DLINQ)generated class that represents Customers, from our good old sample database of Northwind (it's not installled by default in SQL Server 2005, you can get it here).

These are quick step by step to get your feet wet quickly:

In this sample, I create a LINQ to SQL classes and name it Northwind.dbml

vcsharp2008express_itemtemplate

 

Now let's use this new classes, but please pay attention that you have to understand what really is "LINQ to SQL Classes" is.

Basically LINQ to SQL is a quick "one stop shopping ORM" tool that maps your SQL Server database, tables, relations, and also stored procedures into hierarchical objects and CLR methods.

Your database will be mapped into a DataContext, your table will be mapped to

Just add these tables from Northwind to the Northwind.dbml:

  • Customer
  • Order
  • Order_Detail

Just for fun, add the SalesByCategory stored procedure into Northwind.dbml and you'll see this:

Northwind_dbml

Now... it's quite straightforward, right? But, where's the real LINQ?

Ah, LINQ is not pictures and models. This tool simply helps us visualize this code: (in the Northwind.designer.cs)

 

northwind_designer

 

These are the code that represents Northwind database (also conceptually):

 

    public partial class NorthwindDataContext : System.Data.Linq.DataContext
{

private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();

#region Extensibility Method Definitions
partial void OnCreated();
partial void InsertCustomer(Customer instance);
partial void UpdateCustomer(Customer instance);
partial void DeleteCustomer(Customer instance);
partial void InsertOrder(Order instance);
partial void UpdateOrder(Order instance);
partial void DeleteOrder(Order instance);
partial void InsertOrder_Detail(Order_Detail instance);
partial void UpdateOrder_Detail(Order_Detail instance);
partial void DeleteOrder_Detail(Order_Detail instance);
#endregion

public NorthwindDataContext() :
base(global::WinFormDLinq.Properties.Settings.Default.NORTHWNDConnectionString, mappingSource)
{
OnCreated();
}

public NorthwindDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}

public NorthwindDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}

public NorthwindDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}

public NorthwindDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}

public System.Data.Linq.Table<Customer> Customers
{
get
{
return this.GetTable<Customer>();
}
}

public System.Data.Linq.Table<Order> Orders
{
get
{
return this.GetTable<Order>();
}
}

public System.Data.Linq.Table<Order_Detail> Order_Details
{
get
{
return this.GetTable<Order_Detail>();
}
}

[Function(Name="dbo.SalesByCategory")]
public ISingleResult<SalesByCategoryResult> SalesByCategory([Parameter(Name="CategoryName", DbType="NVarChar(15)")] string categoryName, [Parameter(Name="OrdYear", DbType="NVarChar(4)")] string ordYear)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), categoryName, ordYear);
return ((ISingleResult<SalesByCategoryResult>)(result.ReturnValue));
}
}

In VB:

 

Again, quite straightforward, eh?

The rest of the code is the declaration of tables.

Now, again, where's the LINQ, or query, or the code thingy?

I simply use the NorthwindDataContext and create a new instance of it. Then, just get Customer table from it! With a hint from Intellisense. Yes.

 

dlinq_intellisense

 

Okay! Now the LINQ!

In this quick sample, I dump the output of the LINQ to SQL of Customer to an IEnumerable and then put it as a DataSource of a Windows Forms GridView:

in C#:

        private void Form1_Load(object sender, EventArgs e)
{
NorthwindDataContext dbnorth = new NorthwindDataContext();
var qry = from c in dbnorth.Customers
select new { c.CustomerID, c.ContactName, c.CompanyName, c.City };
this.dgvCustomer.DataSource = qry;
}

In VB:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dbnorth As NorthwindDataContext = New NorthwindDataContext
Dim qry = From c In dbnorth.Customers _
Select c.CustomerID, c.ContactName, c.CompanyName, c.City
Me.dgvCustomer.DataSource = qry

End Sub

 

Run it, you'll get the same column results from the select query above:

 

image

 

What if I want to filter it? Hmm... Let's just say I want to get data of customers in London.

Change the code above to this:

In C#:

        private void Form1_Load(object sender, EventArgs e)
{
NorthwindDataContext dbnorth = new NorthwindDataContext();
var qry = from c in dbnorth.Customers
where c.City == "London"
select new { c.CustomerID, c.ContactName, c.CompanyName, c.City };
this.dgvCustomer.DataSource = qry;
}

 

In VB:

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dbnorth As NorthwindDataContext = New NorthwindDataContext
Dim qry = From c In dbnorth.Customers _
Where c.City = "London" _
Select c.CustomerID, c.ContactName, c.CompanyName, c.City
Me.dgvCustomer.DataSource = qry

End Sub

you'll get this:

 

image

Voila!

More productive, right? I just create this sample code less than 5 minutes!

As you see, the "select" is now keyword. So is "where" and "from". But from comes before select, which is different from the original SQL query of SELECT.

Why? Because SQL language is not quite natural in the way the ordinary compiler process. You can't put the "select" first, since you have to know from what kind of set of data you want to manipulate or to select.

The quick notion is: I have to know from what set of data I want to select, then select it. Not the way that SELECT SQL works. Because compiler can't know at first the variables you want to select if you don't define from what data first. Now, enter the world of Declarative Programming!

Why? Because you think what you want to, not how it can be done. Declarative programming is everywhere, from WPF's XAML, to XML Schema, and to quite old domain specific language such as Prolog and our old data centric language (and also domain specific language), SQL query.

Quite funny, isn't it? You've used SQL but you didn't know what kind of taxonomy SQL query was.

But don't be happy soon, C# is not entirely Declarative Programming. It's an imperative programming family member, same as VB.NET.

See? This is why I told you up front, you have to know some concept first. And the depth doesn't stop here. Let's see how the code above is translated into, and I call it, "first phase". But before that, enter another new cool features of C# 3.0 and VB 9.0: type inferencing.

 

Type inferencing

See this:

            var qry = from c in dbnorth.Customers
where c.City == "London"
select new { c.CustomerID, c.ContactName, c.CompanyName, c.City };

You may wonder, is it still type safe? Variable qry has no type defined up front! If you debug and hover your cursor to qry variable, you'll get IEnumerable. Actually, the code above says, "give variable qry the type of the right hand expression has". So, qry has the type of IEnumerable.

I can also create this variable x as Int32 using type inferencing:

            var x = 1;

It's using var and it functions the same as Dim in VB. VB also have it. But var looks like Javascript, and Javascript is dynamic language family member. Enter the world of dynamic language!

But, again, it's up to you to decide whether this is a good or bad news, since C# is not purely dynamic language. For me this fact can be understood perfectly, because C# is intended strongly typed at first, unlike Javascript.

Now, the query code above is translated into this first phase:

            var qry = dbnorth.Customers
.Where(c => c.City == "London")
.Select(c => new { c.CustomerID, c.ContactName, c.CompanyName, c.City });

 

Or in VB:

        Dim qry = dbnorth.Customers _
.Where(Function(c) c.City = "London") _
.Select(Function(c) New With {c.CustomerID, c.ContactName, c.CompanyName, c.City})

 

Have you seen this syntax above before? The "c=>"?

In C#3.0 and VB 9.0, it is called Lambda Expressions. But VB is not taking the same syntax, it's written as new Function which is then translated into Lambda function. VB programmer prefers syntax that's more verbose.

The idea of Lambda Expression itself was taken from a topic of Lambda Calculus, from mathematic foundation. We now turn our journey to the world of exotic Lambda Calculus, but only as an overview in C# or VB view. Now, we're now walking towards new world of Lambda Calculus.

Lambda Calculus (or Lambda Expression in C# 3.0 and VB 9.0)

Now, what is Lambda calculus anyway? It is simply a functional view of expressing your code. But in a deep glass magnifier view, it's a formal system (as in Wikipedia) to investigate function applications and recursion.

In C# and VB, it's a functional way to express delegate and expression tree types.

(To be continued..)

kick it on DotNetKicks.com 

Share this post: | | | |
Posted by eriawan | 3 comment(s)

Yes. It is. I feel dizzy again thinking about what are our youngster wannabe geek doing and thinking today, either they're still studying or being graduated.

I'd experienced many things during my quite long (more than 1 month) silence period. I was doing my coding partially outside Java, the Kalimantan island, while also helping my friends there. My friends are IT lecturers (focusing on software development concepts) from quite a reputable state university and also teaching at other private university as well. Not to mention they have a small software company (call it "micro ISV", just like mine) that sells web solution based on ASP.NET 2.0.

Unspoken yet proven local heroes

Note: I won't mention their company name in here. Also they asked me not to tell their names. But you'll find it on IBM's GSSG website, and they're one of a very rare IBM software development premier partner in Indonesia while also having IBM Rational certifications and MCP certifications in .NET.

I was eager to know many things about educations, especially education IT on Kalimantan. Yes, mostly people of Kalimantan have a warm welcome, comparing to Surabaya. But, I was shocked after visiting and helping them to interview candidates for software developers. Before, they told me, "Don't expect much from fresh graduate locals and from Java graduates." Huh? What's up? They told me that I shouldn't expect graduates to be a good junior software developer to pick.

At first, I didn't believe it. There is should be at least one. Can't find just one? This is impossible.

The truth is more an irony than just a sad fact.

It took almost a week to interview about 30 candidates, but I can only help them for 2 days. Although it's already advertised "looking for C# developer", almost 30% of submitted applicants were failed; they didn't know C# and basic OOP as well.

The rest 70% was quite good at first. They knew basic C# 2.0 and .NET 2.0 concepts, including generics, delegates, using statement (as a deterministic object scope), and collections. But, little they know concepts of .NET CLR. There were fruitful debates at that time, between my friends and me. Finally they agreed to include design pattern and common coding best practices as a requirement. But again, they warned me, "You'll lose many candidates. We won't include that requirement now." Please take note about the word "lose". Lose here doesn't mean that they'll lose good candidates after applying, lose here they'll lose candidates before applying after seeing the fact and yet they mumbled, "What? Design patterns? best practices? no. I don't have that in university".

Ironies

Other ironies comes in again after I met one of candidates at lunch and I was pretending to apply. He told me that most lecturers in his university always giving him doctrines about the best programming language, best OS, and also focusing to learn many programming languages instead of nurturing students to solving business problems, understanding the very basic software development concepts such as DBMS, SDLCs (such as waterfall, iterative, UP), programming paradigms (e.g. imperative programming, functional programming, declarative programming) and many more. He also told me that if he wants to propose .NET 3.0 study as its topic of his final assignment, he'll be out of luck. The majority of his lecturers have rejected him for many non sense reasons such as "We don't use that. What is WPF? No need to learn new things! Just stick to your study and get graduated fast!"

Other candidate that also had lunch with me told me that they somehow got used to think that every concept they've learned from their past universities were enough. No. It's not enough. I calmly told and explained to him that what he'd learned mostly were not conceptual at all. I was having quite painful conversation, since he at first was defensive. After a long persuasion, he realized that he had to learn many basic things that makes a real concepts.

After I discussed this with my friends, they told me that those reasons simply translated to: "I don't know that. Since I don't know WPF and even .NET 3.0 and I won't learn new things since I don't have to. So you as a student simply get back to your chair and just finish your damn study just like others!"

D'uh. I also remembered this bad mentality experience while I was consult my final assignment about 10 years ago. Now still happens.

Heroes and silent screamers

What about my friends as a lecturers? They have gone from "loud scream" to "silent scream". They were known as many bright lecturers and also post graduate students (all of them have at least masters in software engineering and one PhD). Yes, now they're not known from the outside world. But they've been struggling at the university senate level to insert and also assert basic software development concepts while at the same time facing the fact that most of their own colleagues (lecturers, deans) are not willing to shift from programming-language-mastering to instead of conceptual algorithm thinker and problem solver paradigm. They're also always teaching and evangelizing students about the use of best practices, design patterns, and many more. Another best thing: they defend students that have good software developer potentials and have enormous passions of continuous learning and improvements.

Openly against that? Not a chance, they said. Many useless arguments and reasons have been thrown at them. Not to mention threats in form of discipline sanctions because of having against the (bad) habits that have been working for so many years without complaints from students and alumnis.

It's a very fond of them, since my friends love to teach, share, and discuss many things especially about advantages in .NET, software development, and modeling. This is why they're also have quite heroic choices to keep struggling to educate others. Although they don't get paid well by their current universities. They should.

My heart was breaking and I've decided to help them personally and also having helps from friends under my company umbrella, RX Communica.

My proposal to my friends are:

  • Giving additional trainings and workshop about those concepts outside their universities
  • Giving free ebooks such as project Otak as one of first means to accelerate learning programming in Indonesian language while also articulating and exercising other programming paradigms
  • Incubating and sharing some software projects (including their own and jointly developed with RX Communica) to be developed by their potential students
  • Continuously giving constructive critics and suggestion at higher education levels while also giving encouragement to see and understand wider perspective of software developments for almamaters, fellow lecturers, especially IT related lecturers

Closing

What about us? You? Do we care about those who now screaming in silence? Especially for those who keep low profiles and have done many things to make their surroundings and students better.

I do believe we all care. We do care. And by the way, do we have guts to scream in silence in our own local surroundings and our own almamater also? Thanks to them, I do have it now. :)

But I believe we can construct a constructive and intelligent ways to handle this, instead of directly criticize them and hitting their academic pride. Gandhi has proven as one of the best silent screamers. Many other also.

Have any suggestions? Please. you're more than welcome. :)

Share this post: | | | |