Monday, January 23, 2006
Where does XML Data Belong?
What's undisputed is that each element may have no more than one attribute with a given name. That's unlikely to be a problem for a birth date or death date; it would be an issue for profession, name, address, or anything else of which an element might plausibly have more than one. Furthermore, attributes are quite limited in structure. The value of the attribute is simply undifferentiated text. An element-based structure is a lot more flexible and extensible. Nonetheless, attributes are certainly more convenient in some applicaitons. Ultimately, if you're designing your own XML-vocabulary, it's up to you to decide which to use."
from O'Reilly's XML in a Nutshell
Wednesday, January 11, 2006
Monday, December 19, 2005
DirectXmas
http://msdn.microsoft.com/coding4fun/
C# Static Classes
{
// Keep class from being created
private Environment() { }
}
can now be written as: public static sealed class Environment
{
}
The benefit of using a static class instead of the design pattern above is that the compiler can now report an error if any instance methods are accidentally declared.
(from link)
Sunday, December 18, 2005
C# SSH/SFTP Libraries
http://www.tamirgal.com/home/dev.aspx?Item=sharpSsh (free, but perhaps not open source)
http://www.jscape.com/articles/sftp_using_csharp.html ($299)
http://www.eldos.com/sbb/desc-sftp2.php ($559.00)
http://www.sshtools.com/showMaverickDotNet.do ($530.00)
SSH
http://www.routrek.co.jp/en/product/varaterm/granados.html (opensource)
http://www.nsoftware.com/ipworks/ssh/ ($449)
http://www.weonlydo.com/index.asp?showform=SSH.NET ($199)
updated: Thursday, Jan 12, 2006
Saturday, December 17, 2005
C# Using Statement
The using statement allows the programmer to specify when objects that use resources should release them. The object provided to the using statement must implement the IDisposable interface. This interface provides the Dispose method, which should release the object's resources.
(from MSDN VS20005 documentation)
Wednesday, December 14, 2005
Erasures in Java 1.5
..., the generics implementation uses a technique known as erasure. The easiest way to understand erasure is to think of the compiler as performing two distinct tasks. First, it does type checking at compile time using all the type information it has (including the type parameters). Then it transforms the code, using a set of rules that remove all of the type parameters (e.g. all of the parameterized types are mapped to raw types), and inserts a set of casting operations. The complete list of transformations is beyond the scope of this article. However, to give you an idea of what erasure does, here are some of the rules:
- If a class doesn't use type parameters in its definition, erasure doesn't change the class definition.
- Parameterized types "drop" their type parameters.
- Every type parameter is mapped to the appropriate bound. By this, I mean: the type parameter is erased and replaced with the strongest type the compiler can reasonably assert. Thus, in the case of
, T is mapped to Object. In the case of , T is mapped to Rentable, and so on. - Casts are inserted wherever necessary, to ensure that the code compiles.
Structs vs. Classes in C#
Structs vs. Classes
Structs may seem similar to classes, but there are important differences that you should be aware of. First of all, classes are reference types and structs are value types. By using structs, you can create objects that behave like the built-in types and enjoy their benefits as well.
Heap or Stack?
When you call the New operator on a class, it will be allocated on the heap. However, when you instantiate a struct, it gets created on the stack. This will yield performance gains. Also, you will not be dealing with references to an instance of a struct as you would with classes. You will be working directly with the struct instance. Because of this, when passing a struct to a method, it's passed by value instead of as a reference.
Monday, December 12, 2005
LoudNetworks in the Hizouse

Phase 1: Design and implement (efficient) reliable communication between two PCs using a microphone and speaker. CHECK
Phase 2: Design and implement robust ad hoc routing between a set of PCs using sound as their only means of communication. CHECK
Phase 3: Design and implement (efficient, fair, etc.) resource control (that is, sound control) among a set of PCs using sound as their only means of communication. CHECK
Understanding C# Timers
There are three timer controls in Visual Studio and the .NET Framework — the server-based timer you can see on the Components tab of the Toolbox, the standard Windows-based timer you can see on the Windows Forms tab of the Toolbox, and the thread timer that is only available programmatically.
- The Windows-based timer is optimized for use in Windows Forms applications.
- The server-based timer is an update of the traditional timer that has been optimized to run in a server environment.
- The thread timer is a simple, lightweight timer that uses callback methods instead of events and is served by thread-pool threads.
There are two types of threads in Win32 architecture: UI threads, and worker threads. UI threads sit idle most of the time and wait for messages to arrive in their message loops. Once they receive a message, they handle it and then wait for the next message to arrive. Alternatively, worker threads are used to perform background processing and do not use message loops. Both the Windows timer and the server-based timer run using an Interval property. The interval of the thread timer is set in the Timer constructor. The timers are designed for different purposes, as evidenced by their handling of threads:
- The Windows timer is designed for a single-threaded environment where UI threads are used to perform processing. The accuracy of Windows timers is limited to 55 milliseconds. These traditional timers require that the user code have a UI message pump available and always operate from the same thread, or marshal the call onto another thread. For a COM component, this would be detrimental to performance.
- The server-based timer is designed for use with worker threads in a multi-threaded environment. Because they use a different architecture, server-based timers have the potential to be much more accurate than Windows timers. Server timers can move among threads to handle the raised events.
- The thread timer is useful in scenarios where messages are not pumped on the thread. For example, the Windows-based timer relies on operating-system timer support, and if you are not pumping messages on the thread, the event associated with your timer will not occur. The thread timer is more useful in this case.
Windows Form Timer
This class wraps the counters we had in Win32 based on Windows messages. Use this class only if you do not plan to develop a multithreaded application. The Windows Forms Timer component has an Interval property that specifies the number of milliseconds that pass between one timer event and the next. Unless the component is disabled, a timer continues to receive the Tick event at roughly equal intervals of time. This component is designed for a Windows Forms environment. If you need a timer that is suitable for a server environment, see Introduction to Server-Based Timers.
The Interval Property
The Interval property has a few limitations to consider when you are programming a Timer component:
- If your application or another application is making heavy demands on the system — such as long loops, intensive calculations, or drive, network, or port access — your application may not get timer events as often as the Interval property specifies.
- The interval can be between 1 and 64,767, inclusive, which means that even the longest interval will not be much longer than one minute (about 64.8 seconds).
- The interval is not guaranteed to elapse exactly on time. To ensure accuracy, the timer should check the system clock as needed, rather than try to keep track of accumulated time internally.
- The system generates 18 clock ticks per second — so even though the Interval property is measured in milliseconds, the true precision of an interval is no more than one-eighteenth of a second.
Thread safety: Any public static members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Server-Based Timers (System.Timers)
The Timer component is a server-based timer, which allows you to specify a recurring interval at which the Elapsed event is raised in your application. You can then handle this event to provide regular processing. For example, suppose you have a critical server that must be kept running 24 hours a day, 7 days a week. You could create a service that uses a Timer to periodically check the server and ensure that the system is up and running. If the system is not responding, the service could attempt to restart the server or notify an administrator. The server-based Timer is designed for use with worker threads in a multithreaded environment.
Server timers can move among threads to handle the raised Elapsed event, resulting in more accuracy than Windows timers in raising the event on time. For more information on server-based timers, see Introduction to Server-Based Timers.
Key Programming Elements of Server-Based Timers
The Timer component raises an event called Elapsed. You can create handlers for this event to perform whatever processing needs to occur. Some of the more important properties and methods of a Timer component include the following:
- The Interval property is used to set the time span, in milliseconds, at which events should be raised. For example, an interval of 1000 will raise an event once a second.
- The AutoReset property determines whether the timer continues raising events after the given interval elapses. If set to true, the timer continues to recount the interval and raise events. If false, it raises one event after the interval elapses and then stops.
- The Start method sets the timer's Enabled property to true, which allows the timer to begin raising events. If the timer is already enabled, calling the Start method resets the timer.
- The Stop method sets the timer's Enabled property to false, preventing the timer from raising any more events.
Thread safety: any public static members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
Thread-timer (System.Threading.Timer)
Use a TimerCallback delegate to specify the method you want the Timer to execute. The timer delegate is specified when the timer is constructed, and cannot be changed. The method does not execute on the thread that created the timer; it executes on a ThreadPool thread supplied by the system. The callback method executed by the timer should be reentrant, because it is called on ThreadPool threads. The callback can be executed simultaneously on two thread pool threads if the timer interval is less than the time required to execute the callback, or if all thread pool threads are in use and the callback is queued multiple times.
When you create a timer, you can specify an amount of time to wait before the first execution of the method (due time), and an amount of time to wait between subsequent executions (period). You can change these values, or disable the timer, using the Change method.
As long as you are using a Timer, you must keep a reference to it. As with any managed object, a Timer is subject to garbage collection when there are no references to it. The fact that a Timer is still active does not prevent it from being collected.
Note: System.Threading.Timer is a simple, lightweight timer that uses callback methods and is served by threadpool threads. You might also consider System.Windows.Forms.Timer for use with Windows forms, and System.Timers.Timer for server-based timer functionality. These timers use events and have additional features.
Thread safety: This type is safe for multithreaded operations.
Other Timers
1. timeGetTime() : This Windows.DLL call can give you up to 1 microsecond of accuracy on some operating systems; however it can be up to 5 microseconds on Windows NT.
2. System.Tickcount (Environment.TickCount): Gets the number of milliseconds elapsed since the system started.
3. DateTime.Ticks: The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001.
4. QueryPerformanceCounter: often used in C++ Windows games. Provides a high resolution timer of less than 1 microsecond. Not exposed in managed code, so you would have to write a wrapper for it.
References
Programming the Thread Pool in the .NET Framework
System.Timers Namespace
Introduction to Server-Based Timers
Timer Programming Architecture
Introduction to the Windows Forms Timer Component
Other C# Timer Resources
Comparing the Timer Classes in the .NET Framework Class Library (added 12/15/05 5:37PM)
http://www.mvps.org/directx/articles/selecting_timer_functions.htm (added 12/20/05 2:20)
The mvps link is very revealing; it discusses timers in the context of high performance games and evaluates them via benchmarking.
Friday, December 09, 2005
Wednesday, July 13, 2005
XML Newbie
This link from XML.com explains it all.
Sunday, June 26, 2005
VS2005 Visual C# Enhancements
Uses change tracking visualization concept similar to what I proposed in the Augur Eclipse plugin.
Friday, May 06, 2005
Yahoo API vs. Google API
Yahoo! API exposes:
Google API exposes:
- Google's main web index
Note that Yahoo! has taken a much more liberal approach in opening up more facets of their search engine. Based on the following, it's easy to ascertain that Yahoo is really looking to support developers here (perhaps in hopes of motivating developers to use their services over Google). I'm not sure if MSN search has an open API yet. Some other differences I observed while comparing their FAQs are below: Google is in blue while Yahoo! is in red.
Communication Implementation
How does the Google Web APIs service work?
Developers write software programs that connect remotely to the Google Web APIs service. Communication is performed via the Simple Object Access Protocol (SOAP), an XML-based mechanism for exchanging typed information.
Q: Why is Yahoo! using REST?
Our goal is to make Yahoo! Search Web Services available to as many developers as possible. REST based services are easy to understand and accessible from most modern programming languages. In fact, you can get a fair amount done with only a browser and your favorite scripting language.
Q: Does Yahoo! plan to support SOAP?
Not at this time. We may provide SOAP interfaces in the future, if there is significant demand. We believe REST has a lower barrier to entry, is easier to use than SOAP, and is entirely sufficient for these services.
Access Authentication
How do I get access to the Google Web APIs service?
You must first agree to the terms and conditions of the Google Web APIs service and create a Google Account. Google will then email you a license key to use with your Google Web APIs applications. Every time you make a call to the Google Web APIs service, you must include your license key.
Can I create more than one Google Account to get multiple license keys?
No. The terms and conditions you agree to restrict you one account for your personal use. Users who attempt to create more than one account are subject to being banned from the Google Web APIs service.
Q: Do I need a developer token to access Yahoo! API's?
No. Yahoo! Search Web Services use an application ID, not a developer ID.We require an Application ID to be sent with each request. This ID identifies your application, not you, the developer.Application IDs are not used to limit access to the services. Access is rate limited based on the caller's IP address. Each service may have a different access rate limit, and if you exceed that rate, you won't be able to use it for a set amount of time. The documentation for each service lists its rate limit.Best of all you can distribute your great Yahoo! Web Service-powered applications to all of your friends. So long as they're accessing Yahoo! Search Web Services from a different IP, their use will not detract from your limit. If they abuse the service from their computer, your access will not be affected.
Q: What is an Application ID?
An Application ID is a string that uniquely identifies your application. Think of it as like a User-Agent string. If you have multiple applications, you should use a different ID for each one. You can register your ID and make sure nobody is already using your ID on our Application ID registration page.
Rate Limits
How many queries can I issue from my computer programs?
Google provides each developer who registers to use the Google Web APIs service a limit of 1,000 queries per day.
Why is the daily limit only 1,000 queries?
The Google Web APIs service is an experimental free program, so the resources available to support the program are limited.
What if I want to pay Google for the ability to issue more than 1,000 queries per day?
Google is only offering the free beta service at this time. If you would like to see Google develop a commercial service, let us know at api-support@google.com.
Q: What are the limits on how much I can use Yahoo! Search Web Services?
Each service may have different rate limits. See the documentation for each service for more information. (As an aside, the image search has a limit of 5,000 queries per day per ip per application ID!)
Q: How will I know when I hit a limit?
When a rate limit has been exceeded, the HTTP request will receive an error code of 403; along with a standard XML error response. See our rate limiting documentation for details.
Results Per Query
Is there a limit on the number of results I can receive per query?
Yes. You can retrieve a maximum of 10 results per query, and you cannot access information beyond the 1000th result for any given query.
Q: What is the limit on the number of search results I can receive per query?
Each service may have different limits on the number of results you can receive. The documentation for that service will specify the default number and maximum number you can receive. Most services are limited to 50 results per query. Local Search is limited to 20 results per query.
Tracking Usage
How can I track the number of queries I have submitted each day?
Developers need to perform their own tracking of their daily usage.
Q: How can I track the number of queries I have submitted?
If you're a developer, please keep track in your code. Also, consider exposing the counts to the users of your application so they'll have a way to track their usage as well.
Q: How can I track the usage of my applications?
You can get daily usage reports for each of your Application IDs.
