Software Development

  • 软件编程十要

    从事软件开发二十几年了,一直想总结出一些自己应遵循的准则。受“围棋十诀”和“太极拳十要”的启发,从一些书和文章中挑出对自己最有帮助的十条。其中有些条目是相互关联的,都是从不同角度强调如何降低系统复杂度、使系统设计更趋合理。 软件编程十要: 去除冗余 名副其实 单元测试 力求简练 减少关联 重视接口 层次结构 信息隐蔽 风格统一 不断改进 1. 去除冗余 去除冗余是提高软件质量的重要途径。在去除冗余的过程中,我们要把大的函数拆成小的函数,把大的类拆成小的类,引入新的接口、新的抽象类,从而使软件结构更趋合理。 冗余不仅包括完全相同的代码,也包括重复出现的类似的逻辑。如重复出现的switch语句、或if-else if-else语句。这些语句的重复出现,通常表明我们应引入一个抽象类和若干子类,通过多态实现这些逻辑。 冗余就像人身上多余的脂肪,会影响软件的“健康”。随着功能的不断增加,软件很容易变得越来越臃肿。所以,代码复查的一项重要任务就是发现及清除冗余,使软件一直处于结结实实的健康状态。 2. 名副其实 名不正,则言不顺,言不顺,则事不成。 每一个类、每一个函数、每一个变量都应有一个恰如其分的名字。类和变量的名字应是一个名词或被一个形容词修饰的名词,函数的名字应是一个动宾词组。名字应越具体(specific)越好,最好是用现实世界里的名称。如果不能给一个类或一个函数一个具体的恰如其分的名字,那就说明我们的设计有问题,很可能是这个类或函数的聚合度不够高。一个函数应且只应做其名称所规定的工作,而不应顺带做其它工作。 检查不恰当的名字是代码复查中的重要事项。 3. 单元测试 我并没有严格遵守测试驱动开发(Test-Driven Development),但我们会在设计方案确定后,决定写哪些单元测试,并从单元测试入手调试新写的类和函数。 单元测试能在一定程度上确保新增加的代码没有破坏已有的功能,增强我们在对现有程序进行改进时的信心。如果没有单元测试,我们在做较大的调整时会畏手畏脚。 在设计时,注意提高类的可单元测试性也有助于提高设计的质量。单元测试性高的类通常与其它类的耦合度比较低。 单元测试还能在某种程度上起到文档的作用。例如,从单元测试代码中,我们能看到函数如何调用,以及函数的先决条件(pre-condition),后置条件(post-condition)以及类的恒定条件(class… More.

    ·

    ·

    1–2 minutes
  • 软件之形

    从不同层次、不同角度我们能看到软件的不同形状。从这些形状中,我们能大致看出软件的质量。总体来说,好的形状简洁、平衡、统一,能给人以美感。 More.

    ·

    ·

    1–2 minutes
  • Customize WPF ComboBox

    There is a column in the Lines ListView of the Edit Model dialog box of the GeometryViz3D tool for the user to choose the color of the lines. Previously the… More.

    · ,

    ·

    2–3 minutes
  • Dynamically Load DLLs with Exported Classes

    In one of my applications, I need to use some DLLs. There may be several versions of those DLLs installed in different directories, and I need to dynamically decide which… More.

    · ,

    ·

    1–2 minutes
  • From Unmanaged to Managed

    It is not always possible to rewrite your C or C++ legacy applications in .NET languages in one shot. Sometimes you have to do it module by module, step by… More.

    · ,

    ·

    3–4 minutes
  • Linking error LNK2028 and LNK2029

    In one of my C++/CLI projects, I need to use a class exported from a unmanaged DLL. When I build the C++/CLI project, I get two linking errors: LNK2028 and… More.

    · , ,

    ·

    2–3 minutes
  • A Nice Scrum Cheat Sheet

    Found a very nice, concise Scrum Cheat Sheet. More.

    · ,

    ·

    1–2 minutes
  • C++/CLI Cheat Sheet

    In the C++ CLI Cheat Sheet, I tried to list side by side how to do certain things in C++/CLI and C#. More.

    · ,

    ·

    1–2 minutes
  • ListView, ComboBox, and ObservableCollection

    Published an article on CodeProject, discussing about the issues related to binding ObservableCollection to ListView and ComboBox controls. Please read the article here. More.

    · ,

    ·

    1–2 minutes
  • ObservableCollection

    In WPF, we can bind an ObservableCollection<T> object to the ItemsSource property of an ItemsControl, e.g. a ComboBox. When we add or remove an element from the collection, the control… More.

    ·

    ·

    1–2 minutes

Related Articles

Get updates

Spam-free subscription, we guarantee. This is just a friendly ping when new content is out.

Go back

Your message has been sent

Warning
Warning
Warning.