Is it good practice to shorten functions? Like this code for instance:

      using System;
      namespace Hello
          class Program
                public static void Main(String[] args)
                     Write("Hello, World!");

                public static void Write(string s)

                public static void Stagger()

I get lazy and do stuff like that a lot. But is it proper?

marked as duplicate by user22815, user40980, gbjbaanb, Dan Pichelman, gnat Feb 13 '15 at 17:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Short answer: yes. Long answer: read that linked question and the other ones it links to. – user22815 Feb 13 '15 at 3:04
  • Thanks a lot! Sorry, I didn't see those when I was searching. – XiKuuKy Feb 13 '15 at 3:26
up vote 5 down vote accepted

If you do it to improve code readability, this is a good idea.

If you do it to type less, you probably do it wrong.

In your example, your methods don't improve readability; I would even assert that they add complexity and decrease readability:

  • What is Write? Is it writing something to a file? A log? Right, you should read how the method is implemented (since you don't even have XML comments) in order to know what is the purpose of the method.

  • What do Stagger means? Unless this term is used a lot in the application domain, I would avoid it: Console.ReadLine is much more explicit.

They might help you to type less, if you're writing your apps in Notepad. If you use Visual Studio, Intellisense will make those methods irrelevant. Not counting the fact that if you count using the official C# style, you would be writing Program.Write instead of just Write, which means that the number of keys pressed while using Intellisense will be exactly the same.

Not the answer you're looking for? Browse other questions tagged or ask your own question.