First get your environment setup:
1) Get IDE (NetBeans)
(http://wiki.netbeans.org/Scala68v1) for Netbeans 6.8M2 and everything
worked fine (I had to do the tip at the bottom for helloworld to
work).
2) Get Scala Snapshot
The instructions aren’t clear on how to download scala snapshot, so
here is direct link:
http://www.scala-lang.org/archives/downloads/distrib/files/nightly/distributions/scala-2.8.0.latest.zip
3) Play w/ the language online or use REPL
4) Read about the language:
5) Go forth and be productive
alan.huffman JVM Languages, Scala JVM Languages, Scala
Magic strings are nasty for several reasons.
- Compiler will not pick up type-o’s
- When done improperly (e.g. copy / paste ) they can be inconsistent
- If they refer to a property or method, they will break on refactoring or renaming (prop / method)
What to do:
1) Try not to use them.
2) When you must, make constants (do not copy paste)
- Bad: [Dependency("RxDomainUOW")]
- Good:
Create a new Constants class in a top level directory (make it obvious)
public static class AmPharmConstants
{
const String c_RxDomainUOW = "RxDomainUOW";
}
ii. Then use that constant instead
[Dependency(AmPharmConstants.c_RxDomainUOW)]
3) Rather than magic strings to name a property you can use a class in AmMedUtils: ReflUtil
- Instead of this: this.PropertyChange(this, “PublishedOrders”);
- Use this: this.PropertyChange(this, ReflUtil.PropName(() => PublishedOrders));
< CLASS ReflUtil >
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
namespace AMFW.Utilities
{
/// <summary>
/// From:
/// http://handcraftsman.wordpress.com/2008/11/11/how-to-get-c-property-names-without-magic-strings/
/// </summary>
public static class ReflUtil
{
/// <summary>
/// string name = ReflectionUtility.PropName(() => default(Sample2).Foo);
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="expression"></param>
/// <returns></returns>
public static string PropName<T>(Expression<Func<T>> expression)
{
MemberExpression body = (MemberExpression)expression.Body;
return body.Member.Name;
}
}
}
alan.huffman C# Best Practices, C#, Coding Styles, Reflection