Wah, Mibbit udah ngeluarin ceting yg pake automatic translation. Mudah-mudahan nantinya bisa jadi instrumen untuk achieve Turing test. Kapan yah?
Hey Microsofties, when will you release a cool App Engine like Google App Engine. So we can have a development environtment with C# and ASP.Net built-in.
Let's say you have this solution structure:
Solution 'ConsoleApplication2' (2 projects)
|- ClassLibrary1
| |- Class1.cs
|
|- ConsoleApplication2
|- Program.cs
In Class1.cs, you define:
namespace ClassLibrary1
{
public class Class1
{
public const int ItemPrice = 500;
}
}
In Program.cs, you define:
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(ClassLibrary1.Class1.ItemPrice * 2);
Console.ReadLine();
}
}
}
You have deployed your ConsoleApplication2 application into two different PCs.
Now, you change the value of ItemPrice constants into 1000 and then you compiled the ClassLibrary1 library.
How do you deploy the changes to the two PCs?
Do you just need to deploy the ClassLibrary1 assembly or else?
And why?
Without using your compiler, guess what will be the output of this code:
static void Main(string[] args)
{
Sample<string, int> s = new Sample<string, int>("A", 0);
Console.WriteLine(s.PropA + s.PropB);
Console.ReadLine();
}
public class Sample<A, B>
{
public A PropA = null;
public B PropB = null;
public Sample(A a, B b)
{
PropA = a;
PropB = b;
}
}
and why?
Without using your compiler, guess what will be the output of this code:
static void Main(string[] args)
{
string s = "A";
s = string.Concat(s, "B");
s = string.Join(s, new string[] { "1", "2", "3" });
Console.WriteLine(s);
Console.ReadLine();
}
and why?
Di sono orang-orang pada ngeluangin waktu untuk ngerjain project kayak MonoRail, Log4Net, Mono, etc dan itu dibikin open source dengan salah satu harapan mereka bisa jualan konsultansi. Nah kalo di sini? Yang bisa dijual apaanya ya?
Any comment?
The answer for this post is here.
Tha'ts why I love hashtable.
Hey Microsofties!!
When will you release a cool dynamic language like Phyton or Ruby so we can have
Django or
RoR in .Net world?
Your MVC design and EntLib is sucks!!!!
I have a list of integer that contains four data, let says I use an array list:
System.Collections.ArrayList arl = new System.Collections.ArrayList();
arl.Add(1);
arl.Add(0);
arl.Add(1);
arl.Add(1);
I want to remove all zeros from the list but I must iterate the list, so I use this algorithm to achieve it:
for(int i = 0; i < arl.Count; i++)
{
if(((int)arl
) == 0)
{
arl.RemoveAt(i);
i--;
}
}
How to do it in VB? Any one knows?
It seems simple, but remember, nothing as simple as it seems.
"A good scientist is a person with original ideas. A good engineer is a person who makes a design that works with as few original ideas as possible." - Freeman Dyson
Are you a scientist or an engineer?
I was a C++ and Delphi programmer when I was in a college and on my first job. Because of job market reason, I had to switched to RAD tools like VB and C#. Now, I have forgotten many of Windows API stuff like WM_QUIT, PostQuitMessage, etc.
Starting from now, I will revisit my journey on learning Win32 programming with pure Windows API with goals to create an object-oriented Win32 GUI framework.
Stay tune!
Kemaren malam, Rabu 9 Agustus 2007, gw baru beli beberapa buku di Gramedia Matraman. Pulang ke rumah, gw asyik baca majalah Marketing yang gw beli beberapa hari yang lalu. Saking asyiknya, gw sampe ga sadar waktu udah menunjukkan pukul 00:00, gw belum sholat Isya, jadi gw wudhu. Sehabis wudhu, sekitar jam 00:12 dini hari, iseng-iseng gw buka salah satu buku yang gw beli.
Baru baca bagian kata pengantar:
Eh, tiba-tiba, gw denger pintu kamar gw bergerak-gerak dan berbunyi agak keras. Kaget juga! Dan gak lama kemudian, meja komputer gw bergoyang-goyang dan gw juga merasakan goyangan yang cukup keras. Ini pasti gempa!!! Khawatir terjadi musibah seperti di Surabaya beberapa waktu lalu, gw bangunin nyokap. Alhamdulillah, gempanya berakhir dan gak sampe meningkat menjadi musibah nasional.
Ini merupakan gempa ke-2 terbesar yang pernah gw rasain, mungkin ke-2 terbesar di Jakarta, karena dulu sekitar tahun 1996, Jakarta juga pernah diguncang gempa. Saat itu gw lagi di toko buku Gramedia Citraland, di lantai paling atas. Gw lagi jongkok, sambil baca buku dan tiba-tiba gw merasakan kepala gw agak pusing dan badan gw bergoyang-goyang. Gw masih belum sadar. Enggak lama, gw nengok ke belakang....Ternyata orang-orang lagi pada berlarian, panik :)
Hmm...Kebetulan atau gimana yah? Apakah gempa dini hari ini disebabkan oleh kedahsyatan buku yang gw baca? ;-)
Untuk yang udah married mungkin lagi 'digoyang' yang lain, tapi buat bujangan kayak gw, kok malah digoyang bumi :-P.
If you are a business application developer and you're writing you're application using entity paradigm that is you are using object/class to represents your database tables then I am absolutely sure that you had been writing this type of code many times:
public class Person
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private DateTime _dateOfBirth;
public DateTime DateOfBirth
{
get { return _dateOfBirth; }
set { _dateOfBirth = value; }
}
// etc..
}
Unless you have written your own code generator or any other third party tools to automatically generate the code for you based on your database design then this article is for you.
In this Part I, I will only cover the theory not the implementation. I hope the reader will understand how to make one and write their own implementation but I'll wrote the implementation in the Part II.
The Theory
OK, here is the theory:
All you have to do is just find a way to read all the tables (including the views if you wish) contains in the database that you want to generate the code. Create a class to handle the code generation for a table. You have to map the sql data type with the equivalent .Net data type. Generate the code for each tables by passing it to your table class generator.
So, what you have to do is:
1. Find a way to read all the tables. There are many ways to solve this.
2. Create a class which responsible to generate the code for a table. If you do this, you have divide your problem into a smaller problem and it will be easier for you to conquer the problem.
3. Map the sql data type to .Net equivalents. This is up to you but you can find the reference table in MSDN.
Conclusion
OK, that's it. There is a third party scripting tools like CodeSmith that already handled the point 1 but you have to learn how to use it first :). Like I said I'll just covered the theory for now and its up to you to implement it. If you have any questions, you can put it on the comments box.
From all fundamental data structure, hashtable is my favorite one. I know about this data structure not from college, in fact I never heard about it when I was studying in my college, my first time encounter with she is when I involved in a project that using the Beta version of .Net Framework as the tools.
The Application
After that first encounter, hashtable always come in handy whenever I need it. It was helped me when I was:
1. Developing an excel like pivot table program and print it using GDI+. As far as I can remember, in this project, I use a hashtable to group and summarize the data also to remember the cell boundaries when printing the displayed data in the grid. Well, thanks to hash table this program run faster than MS Excel and can load bigger data (millions of data) than the MS Excel version. This project is a proof that hashtable is good to handle big data.
2. Programming in JavaScript. I think the core point of JavaScript is hashtable. Because every array in javascript is also a hashtable. Every object is a hashtable.
3. Developing IrwanLang. I use hashtable to store list of variable and list of function declared so I can check if a variable/function is already defined or not by just passing the variable/function name to my hashtable friend.
3. Developing many more projects. I can't recall them again because I use hashtables unconsciously.
For me, a hashtable is just a love at the first sight, because I can use string or any kind of object as the index, more appropriately as the key, I don't have to do any calculation, just use it instantly.
In the beginning, I am courius how hashtable do his magic. Well, here is the fundamental theory of why people invented hashtable.
The Theory
Imagine that you have to build a software, a phonebook software, just like the one that you have on your cell phone. When there is someone calling, the software will display the name of the caller. So, the phone number is using as the key. Just forget about the persistent mechanism for now, let say the data is stored in volatile memory only. So the phone must always on, if it turned off, well the data will be gone :)
The requirements above, stated implicitly that the name retrieval function must be fast, so an algorithm with O(1) performance is preferred.
So with which data structure will you solve the problem?
Let's say there is four people that you'll have to add. We'll use Jakarta's phone number format for simplicity.
P1: 5357288
P2: 8849872
P3: 4358999
P4: 5697777
Those numbers are sparse, they are far away from each other. If you use array, then your data structure will look like this:
Figure 1. Phonebook data structure using an array
Well, what do you think with that? Is it a good solution? I don't think so, because it will consume a lot of memory just to store those four values.
Hmm...can we optimize it? Are there any alternatives?
Imagination is More Important Than Knowledge
What about linked list? Yeah, linked list can store those four numbers efficiently but what about its retrieval performance? Linked list is not adequate in terms of retrieval performance. Why?. (You can submit your answers by using the comments box below).
We need another kind of mechanism to achieve O(1) retrieval. Array is fast for retrieval, insertion too. OK, let's optimize our array.
After imagining for a while, I come up with this.
How about if we have this mechanism:
Figure 2. Optimizing the array by using the index calculator
We need to transform those numbers into the appropriate index of the cell in our array.
Hmm...Lets say I have an array with 10 cells. How do I transform those numbers to a valid array index? Think hard....!!!
OK, I think I've found the solution. We can use modulo.
10 mod 3 = 1
50 mod 3 = 2
90 mod 3 = 0
Well, modulo always yield result that is small number. But how can we makesure that the result will not give us index out of bounds error. Lets solve it heuristically. Let use our array size as the divisor.
5357288 mod 10 = 8
8849872 mod 10 = 2
4358999 mod 10 = 9
5697777 mod 10 = 7
Hey!!! I think we are quite sure that with modulo we won't have index out of bounds errors.
Those process is called hashing and the function we use, that is modulo by the array size, is called hash function. But can you help me to make sure our hash function is correct? (You can answer it mathematically or heuristically, I love to see both).
The Implementation
OK, lets implement our algorithm. Well, its your job to implement it :). Share it to the world ya! :)
Is it possible for two or more numbers to produce the same array index? If it yes, how can we solve it? Hmm...one problem solved comes another problem. That's why I love software development :-P
Can you give reason why the retrieval performance is O(1)? How about with its insertion and deletion?
Well, if you have reached to this section. Congratulations!!! You have build your own hashtable.
Conclusion
This is just an introduction to hashtable. Next time I will write more advance topic about hashtable. But from now on, use it. You don't have to write your own hashtable class, unless you really..really need it, because .Net already provided you with one. Especially in JavaScript :)
What if I have a language that run in a simple machine that consists of an array of 300 byte cells initialized to zero, a moveable pointer to the array (initialized to point to the lefmost byte of the array), and two streams of bytes for input and output using ASCII as the character encoding.
The language itself has eight commands:
> : increment the pointer (to point to the next cell to the right)
< : decrement the pointer (to point to the next cell to the left)
+ : increment (increase by one) the byte at the pointer
- : decrement (decrease by one) the byte at the pointer
. : output the value of the byte at the pointer
, : accept one byte of input, storing its value in the byte at the pointer
[ : jump forward to the command after the corresponding ] if the byte at the pointer is zero
] : jump back to the command after the corresponding [ if the byte at the pointer is nonzero
So, can you answer the question?
More Posts
Next page »