Five Simple Rules to Be Happy

By Kuristosu Dei
Remember the five simple rules to be happy:

1. Free your heart from hated.

2. Free your mind from worries.

3. Live simply.

4. Give more.

5. Expect less.








 

Code Design and Visualization with Visual C# 2005

By Kuristosu Dei
Dev Source, May, 2005 by Joe Mayo

One of the exciting new features in Visual C# 2005 is Class Diagrams. Class diagrams give developers IDE support for visualizing the static structure of code. Furthermore, the class diagram capability enables visual design of new code. This article discusses both of these exciting new features, and shows you the details of making them work for you.

Why Visualization?

To understand the need for code visualization, think of how many times you've begun maintenance work on a piece of code that someone else wrote. Similarly, ponder the times you've returned to your own code, after more than a week of not working on it. In most cases, it takes time to acclimate yourself to how the pieces fit together.

The Class Diagram helps in this process, by allowing you to visualize the structure of an application with a graphical representation of your code. It displays types, their members, and associations between them. The result is that you now have an opportunity to get up-to-speed in understanding the makeup and relationships of objects in your application quicker than reading code alone.

The Initial Class Diagram

The process of visualization assumes you have some code that has already been written. It could have come from someone else, or could potentially be code that you wrote yourself. To get started, the code must be a part of a Visual C# project. To pull the code in from somewhere else, open the project you want to work with, right-click on the project in Solution Explorer, and select Add/Existing Item. Listing 1 shows some code I wrote to demonstrate visualization of various types and their relationships.

Listing 1. The purpose of this listing is to demonstrate the visualization process and how each type appears in the Class Diagram.

using System;

namespace Visualization
{
class Program
{
private MyDerivedClass m_derived = new MyDerivedClass();

public MyDerivedClass MyDerivedClass
{
get { throw new NotSupportedException(); }
set { }
}

static void Main(string[] args)
{
}
}

public interface IMyInterface
{
void MyRequiredMethod();
int MyRequiredProperty { get; set; }
}

public class MyBaseClass
{
public void MyRequiredMethod() { }

private int[] m_myNums = { 1, 2, 3 };

protected int this[int index]
{
get { return m_myNums[index]; }
set { m_myNums[index] = value; }
}

protected internal void MyBaseMethod() { }
}

public sealed class MyDerivedClass : MyBaseClass, IMyInterface
{
private int m_myInt;

public int MyRequiredProperty
{
get { return m_myInt; }
set { m_myInt = value; }
}

public void MyDerivedMethod()
{
}

public event MyDelegate MyEvent;
}
public class MyClass : IMyInterface
{
private int m_myInt;

public int MyRequiredProperty
{
get { return m_myInt; }
set { m_myInt = value; }
}

public void MyRequiredMethod()
{
throw new Exception("The method or operation is not implemented.");
}

public event MyDelegate MyEvent;
}

public struct MyStruct : IMyInterface
{
private int m_myInt;

public int MyRequiredProperty
{
get { return m_myInt; }
set { m_myInt = value; }
}

public void MyRequiredMethod()
{
throw new Exception("The method or operation is not implemented.");
}

public event MyDelegate MyEvent;
}

public delegate void MyDelegate();
}

To visualize the code in Listing 1, right-click on its containing project in Solution Explorer and select View Class Diagram. This produces the image shown in Figure 1.

Figure 1. Class Diagram of Code from Listing 1 produced from Visual C# 2005.

Types and Shapes

As shown in Figure 1, each type has a distinctive shape and gradient color. Classes, such as MyClass and Program, have a rectangle with rounded corners and a blue color. Interfaces, such as IMyInterface, are green rounded rectangles, and delegates, such as MyDelegate, are violet rounded rectangles. Structs, such as MyStruct, are straight rectangles in blue.

Inheritance relationships are displayed with a closed empty arrow, as demonstrated where MyDerivedClass inherits MyBaseClass. Also notice the interface inheritance relationship between MyDerivedClass and IMyInterface, which is represented with a lollipop. Both MyStruct and MyClass inherit IMyInterface, but I suspect there is a bug in my version of the Beta 2 software that doesn't display the label by the lollipop.

There is a difference between the MyDerivedClass and other classes. Its border is thicker because MyDerivedClass is sealed.

Inside Types

Initially, each type in a diagram has a chevron that points downward. When you click the chevron, it points upward, and the type expands to show its members. By default, these members are categorized by Fields, Properties, Methods, and Events. Indexers are included in the Properties category. Figure 2 shows the expanded MyDerivedClass diagram, which includes each category.
 

Understanding C# Class and Member Modifiers 2

By Kuristosu Dei
The New keyword is usually seen as an operator that is used to create new objects. It also plays a role as a modifier in class definitions and has a totally different meaning. It is used when you want a member of a derived class to hide a member of the same name in the base class. For example, here's a simple class:

public class A
{
public int total;
}

Suppose you want to derive a new class from A and give it a member called total that is type float. Here's where you need to use the new modifier:

public class B:A
{
new float total;
}

You don't see new used very often, for two reasons. First of all, omitting new does not prevent compilation; it just results in a warning. The class works as if you had included new — that is, the member in the derived class hides the same-name member in the base class. It can be included as an indication, perhaps to some maintenance programmer down the road, that you really did mean to include the member in the derived class even though the base class already had one of that name. Second, it is usually preferred to explicitly override the base class member using the override keyword.

I hope that this brief exposition has helped you to understand all these keywords and their uses. For convenience I have summarized this information in the following table and included the Visual Basic counterparts for each of the C# keywords.

C#

VB

Class cannot be inherited (cannot be a base class).
Sealed

NotInheritable

Class cannot be instantiated but only used as based class and/or with abstract methods.

Abstract

MustInherit

For class members: member is accessible only from the class in which it is declared. For classes: only allowed on nested classes to restrict access to the nested class to the containing class..

Private

Private

For class members: member is accessible only from types defined in the same assembly. For classes: class is accessible only from types in the same assembly.

Internal

Friend

For members: member is accessible from the class in which it is declared and from any class derived from that class.

Protected

Protected

Combines the access of Protected and Internal for a class member

Protected Internal

Protected Friend

Access is not restricted.

Public

Public

Hides a member inherited from a base class.

New

Shadows

Copyright © 2005 Ziff Davis Media Inc. All Rights Reserved. Originally appearing in Dev Source.
 

Understanding C# Class and Member Modifiers

By Kuristosu Dei
Dev Source, May, 2005 by Peter Aitken
In my opinion, one of the best things about programming in C# is the ability to use true object-oriented techniques. But let's face it — for those of us who were brought up with procedural programming (and I bet that's just about 100% of us!), getting your mind wrapped around the concepts of OOP can be tough. It is not made any easier by all those strange-sounding keywords that can be used when defining classes and class members. Friend? Sealed? Abstract? Pass the aspirin! In this article, I try to bring some clarity to this topic.

Access Modifiers

Some of the keywords you use with classes are access modifiers. In other words, they control the extent to which the class is available to code (similar to variable scope). For example, look at this code which creates, or attempts to create, an instance of the class MyClass:

MyClass cls = new MyClass();

If MyClass is accessible at the location where this code is located, there is no problem. If MyClass is not accessible, you get a compile error, to the effect that the type MyClass cannot be found.

Additional confusion comes from the fact that some of the access modifiers can be used with class members (methods, for example) as well as with the classes themselves. Let's take a look at these access modifier keywords, first as they apply to classes and then as they apply to class members.

Class Access Modifiers
The default class access modifier is internal. This makes the class accessible from other classes in the same assembly. By default, I mean that this is the access provided if you include no access modifier keyword. Thus, these two are equivalent:

class MyClass { ... }

internal class MyClass { ... }

The default internal access is appropriate for the vast majority of classes you will create.

Less restrictive access is provided by the public keyword. A public class is accessible without restriction. In practical terms, it means that a public class in one assembly is accessible from another assembly:

public class MyClass { ... }

The most restrictive class access is created with the private keyword. You can use private only with a nested class, one that is defined within another class. The result is that the private class is accessible only from within the containing class:

public class OuterClass
{
...
private class InnerClass
{
}
}

Member Access Modifiers

By default, class members are private, which means they are accessible only from code in the class. You can include the private keyword or omit it with the same effect:

SomeMethod() { ... }
private SomeMethod() { ... }

Slightly less restrictive is protected access, obtained with the (you guessed it) protected keyword. A protected member is accessible in the type in which it is defined and in types derived from that type:

protected SomeMethod() { ... }

Thus, if you create a protected member in class A and then create class B that inherits from A, the member will be available to code in class B.

Internal access means the member is accessible to other types that are defined in the same assembly:

internal SomeMethod() { ... }

You can combine the protected and internal keywords to provide member access that is a combination of the two:

protected internal SomeMethod() { ... }

The least restrictive access is obtained with the public keyword. Use the public keyword to make a class member freely accessible inside and outside of the class.

public internal SomeMethod() { ... }

Other Class Modifiers

Some class modifiers are not related to access at all but place limitations on inheritance and instantiation. By default, a class can be instantiated — in other words, you can create an object from it — and it can also be used as the base class for a new class. You can modify this with the abstract and sealed keywords.

A class defined using the abstract keyword cannot be instantiated. Thus if you have a class definition like this :

abstract class MyClass { ... }

you cannot do this:

MyClass cls = new MyClass(); // Causes compilation error.

Abstract classes are usually created to serve as base classes. The .Net Framework itself contains many base classes. For example, your program may need three classes that have many members in common, but differ in a few crucial details. A good programming strategy would be to create an abstract class that contains all the common elements, then create the three individual classes that each inherits from the abstract class. Abstract classes can also be used to provide functionality without data storage, such as the Math class in the .Net Framework.

A sealed class is sort of the opposite of abstract. It can be instantiated but cannot serve as a base class. The primary reason to seal a class is to prevent your users from fiddling around with it and breaking it (and of course blaming you, usually!). It's also the case that sealing a class permits certain compiler optimizations that are not possible with non-sealed classes. Obviously, a class cannot be both sealed and abstract.
 

Apple releases software version 1.0.3 for iPod classic, nano 3G

By Kuristosu Dei
Alongside the release of iPod software version 1.2.3 for the fifth-generation iPod, Apple today rolled out iPod software version 1.0.3 for the iPod classic and iPod nano (with video). Again, the release notes state that the update simply contains “bug fixes.” More specifically, it appears the update fixes an issue with the iPod nano’s clock, and addresses a problem where play counts of songs were affected by games. On the iPod classic, the update appears to fix some issues with Cover Flow, and provides a solution for the “spinning disk” problem. iPod software version 1.0.3 for the iPod classic and iPod nano (with video) is available now via the Update feature in iTunes.
 

I Pod

By Kuristosu Dei
With up to 160GB of storage, iPod classic lets you carry everything in your collection — up to 40,000 songs or up to 200 hours of video — everywhere you go.iPod classic puts your entire music and video collection in your pocket.iPod is a brand of portable media players designed and marketed by Apple and launched in October 2001. The line-up currently consists of the original style hard drive-based flagship iPod classic, the iPod touch, the mid-level video-capable iPod nano, and the low-end screenless iPod shuffle. Former products include the compact iPod mini (replaced by the iPod nano) and the high-end spin-off iPod photo (re-integrated into the main iPod classic line). iPod classic models store media on an internal hard drive, while all other models, aside from the Microdrive-based mini, use flash memory to enable their smaller size. As with many other digital music players, iPods can also serve as external data storage devices.

Apple's iTunes software is used to transfer music to the devices. As a jukebox application, iTunes stores a music library on the user's computer and can play, burn, and rip music from a CD. It also transfers photos, videos, games, and calendars to those iPod models that support them. Apple focused its development on the iPod's unique user interface and its ease of use, rather than on technical capability. As of September 2007, the iPod had sold over 110 million units worldwide (stated in "The Beat Goes On" conference) making it the best-selling digital audio player series in history.

History and design

iPod came from Apple's digital hub strategy,[1] when the company began creating software for the growing market of digital devices being purchased by consumers. Digital cameras, camcorders and organizers had well-established mainstream markets, but the company found existing digital music players "big and clunky or small and useless" with user interfaces that were "unbelievably awful,"[1] so Apple decided to develop its own. Apple's hardware engineering chief, Jon Rubinstein, ordered by Steve Jobs, assembled a team of engineers to design it, including Tony Fadell, hardware engineer Michael Dhuey, and design engineer Jonathan Ive, with Stan Ng as the marketing manager. The product was developed in less than a year and unveiled on October 23, 2001. CEO Steve Jobs announced it as a Mac-compatible product with a 5 GB hard drive that put "1000 songs in your pocket."

Uncharacteristically, Apple did not develop iPod's software entirely in-house. Apple instead used PortalPlayer's reference platform which was based on 2 ARM cores. The platform had rudimentary software running on a commercial microkernel embedded operating system. PortalPlayer had previously been working on an IBM-branded MP3 player with Bluetooth headphones.[2] Apple contracted another company, Pixo, to help design and implement the user interface, under the direct supervision of Steve Jobs.[1] Once established, Apple continued to refine the software's look and feel. Starting with iPod mini, the Chicago font was replaced with Espy Sans. Later iPods switched fonts again to Podium Sans — a font similar to Apple's corporate font Myriad. iPods with color displays then adopted some Mac OS X themes like Aqua progress bars, and brushed metal in the lock interface. In 2007, Apple modified the iPod interface again with the introduction of the sixth-generation iPod classic and third-generation iPod nano by changing the font to Helvetica, and in most cases, splitting the screen in half by displaying the menus on the left and album artwork, photos, or videos on the right (whichever was appropriate for the selected item).

Trademark

The name iPod was proposed by Vinnie Chieco, a freelance copywriter, who (with others) was called by Apple to figure out how to introduce the new player to the public. After Chieco saw a prototype, he thought of the movie 2001: A Space Odyssey and the phrase "Open the pod bay door, Hal!", which refers to the white EVA Pods of the Discovery One spaceship.[1] Apple researched the trademark and found that it was already in use. Joseph N. Grasso of New Jersey had originally listed an "ipod" trademark with the U.S. Patent and Trademark Office in July 2000 for Internet kiosks. The first ipod kiosks had been demonstrated to the public in New Jersey in March 1998, and commercial use began in January 2000. The trademark was registered by the USPTO in November 2003, and Grasso assigned it to Apple Computer, Inc. in 2005.[3]

Software

iPod can play MP3, AAC/M4A, Protected AAC, AIFF, WAV, Audible audiobook, and Apple Lossless audio file formats. The iPod photo introduced the ability to display JPEG, BMP, GIF, TIFF, and PNG image file formats. Fifth and sixth generation iPod classics, as well as third generation iPod nanos, can additionally play MPEG-4 (H.264/MPEG-4 AVC) and QuickTime video formats, with restrictions on video dimensions, encoding techniques and data-rates. Originally, iPod software only worked with Macs; however, starting with the second generation model, iPod software worked with Windows and Macs. Unlike most other media players, Apple does not support Microsoft's WMA audio format — but a converter for WMA files without Digital Rights Management (DRM) is provided with the Windows version of iTunes. MIDI files also cannot be played, but can be converted to audio files using the "Advanced" menu in iTunes. Alternative open-source audio formats such as Ogg Vorbis and FLAC are not supported without installing custom firmware onto the iPod.

The iPod is associated with one host computer. Each time an iPod connects to its host computer, iTunes can synchronize entire music libraries or music playlists either automatically or manually. Song ratings can be set on the iPod and synchronized later to the iTunes library, and vice versa.

File storage and transfer

With the exception of the iPod touch, [citation needed] all iPods can function as mass storage devices to store data files. If the iPod is formatted on a Mac OS X computer it uses the HFS+ file system format, which allows it to serve as a boot disk for a Mac computer.[9] If it is formatted on Windows, the FAT32 format is used. With the advent of the Windows-compatible iPod, iPod's default file system switched from HFS+ to FAT32, although it can be reformatted to either filesystem (excluding the iPod shuffle which is strictly FAT32). Generally, if a new iPod (excluding the iPod shuffle) is initially plugged into a computer running Windows, it will be formatted with FAT32, and if initially plugged into a Mac running Mac OS X it will be formatted with HFS+.

Unlike many other MP3 players, simply copying audio or video files to the drive with a typical file management application will not allow iPod to properly access them. The user must use software that has been specifically designed to transfer media files to iPods, so that the files are playable and viewable. Aside from iTunes, several alternative third-party applications are available on a number of different platforms.

iTunes 7 and above can transfer purchased media of the iTunes Store from an iPod to a computer, provided that the DRM media is transferred to any of the five computers allowed for authorization with DRM media.

Media files are stored on the iPod in a hidden folder, together with a proprietary database file. The hidden content can be accessed on the host operating system by enabling hidden files to be shown. The audio can then be recovered manually by dragging the files or folders onto the iTunes Library or by using third-party software.

Equalizer

If the sound is enhanced with the iPod's software equalizer (EQ), some EQ settings — like R&B, Rock, Acoustic, and Bass Booster — can cause bass distortion too easily.[10][11] The equalizer amplifies the digital audio level beyond the software's limit, causing distortion (clipping) on songs that have a bass drum or use a bassy instrument, even when the amplifier level is low. One possible workaround is to reduce the volume level of the songs by modifying the audio files.