如何成為人盡皆知的C#開發人員

來源:互聯網
上載者:User

    這篇指導最終會教你如何成為你的同事中最受歡迎的人,您將成為他們在休息和工作時間的聊天的英雄,甚至可以說這篇指導能協助減少你的工作,你能得到你的同事的慷慨協助,他們想幫你做你的工作。因為你的名聲!

1、變數命名可以顯示你創造潛力,不要使用標識法和準則來煩擾你自己,這些全都會限制你的靈感,如果您使用一個未知的命名方案,你會得到讚揚,您的同事會尊敬你。

bool rAgeaggainStmaShine = false;
int dd44 = 12;
bool dude = true;

2、成為天才,給方法和參數取一些耐人尋味的名字

public int ViriableInflationModusOperandi(int variable, int inflator)
{
    return variable * inflator;
}

3、用非常專業態度去注釋你的代碼。注釋有助於正確的理解你的代碼。

// This variable is named after my mom. Wyburga-Thomasia Flandrina. Remember it!
long wtf = 1;

4、你的代碼不要寫太多的注釋。過多的注釋讓你的同事感到緊張-因為你認為他們不明白?如果你讓他們有機會思考,他們會尊重你。

代碼

/// <summary>
/// Perform image check.
/// </summary>
public static void ImageRoutine(Image image)
{
    if ((image != null) && (imageInfoList != null))
    {
        bool isReaderLockHeld = rwImgListLock.IsReaderLockHeld;
        LockCookie lockCookie = new LockCookie();
        threadWriterLockWaitCount++;
        try
        {
            if (isReaderLockHeld)
            {
                lockCookie = rwImgListLock.UpgradeToWriterLock(-1);
            }
            else
            {
                rwImgListLock.AcquireWriterLock(-1);
            }
        }
        finally
        {
            threadWriterLockWaitCount--;
        }
        try
        {
            for (int i = 0; i < imageInfoList.Count; i++)
            {
                ImageInfo item = imageInfoList[i];
                if (image == item.Image)
                {
                    return;
                }
            }
        }
        finally
        {
            if (isReaderLockHeld)
            {
                rwImgListLock.DowngradeFromWriterLock(ref lockCookie);
            }
            else
            {
                rwImgListLock.ReleaseWriterLock();
            }
        }
    }
    //Everything is done. Return.
}

5、使用封裝。這是物件導向的關鍵原則之一。比較這兩個例子:

Example #1:

public int AddTwo(int arg)
{
    return arg + 2;
}

public int AddOne(int arg)
{
    return arg + 1;
}

public void Main()
{
    int calc = AddOne(AddTwo(5));
}

 Example #2:

public void Main()
{
    int calc = 5 + 2 + 1;
}

很明顯,Example #1看起來更加穩固。它有更多的代碼,一切都被封裝,並且代碼看起來令人印象深刻。

6、編寫更少的代碼。這將導致更少的錯誤,更少的支援的時間和更多的娛樂時間。考慮下面的結構:

common.js:

代碼

function deleteUser(userId)
{
    $.get("sqlengine.ashx",
    { sql: "delete from [User] where Id = " + userId  } );
}

function insertUser(userName)
{
    $.get("sqlengine.ashx",
    { sql: "insert into [User] values ('" + userName + "')" } );
}

sqlengine.ashx:

代碼

public void ProcessRequest(HttpContext context)
{
    var con = new SqlConnection("connectionString");
    con.Open();
    var cmd = new SqlCommand(context.Request.QueryString["sql"]);
    cmd.Connection = con;
    cmd.ExecuteNonQuery();
    con.Close();
}

你得到:注重AJAX化的頁面,快速開發,多層體繫結構。

7、編寫天才的代碼。你的同事會感謝你的見解。

編寫:

int year = 0x000007D9;

而不是:

int year = 2009;

編寫:

var sb = new StringBuilder();
sb.Append(“Error:”);
sb.Append(2001);
sb.Append(“.”);
return sb.ToString();

而不是:

return string.Format(“Error: {0}.”, 2001);

編寫:

代碼

/// <summary>
/// Does mysterious transformation of TRUE to FALSE and vice versa.
/// </summary>
public static bool TheGreatLifeTransformation(bool valueToTransform)
{
    if (valueToTransform == true)
    {
        return false;
    }
    if (valueToTransform == false)
    {
        return true;
    }

    throw new ArgumentOutOfRangeException();
}

而不是:

!value

     如果您按照這些簡單的步驟去做,你的名字將很快被你的所有同事知道。你將是一個非常受歡迎的人-你的同事會向你提供建議,聊天和握手。其中一些同事可能會問你的秘密。如果發生這種情況,你可以給他們如下回覆(要用導師的聲音說):
"Writing code is a transcendental process of transformation of infinite chaos into finite reality with coherence, of course"。

 參考原文:http://www.codeproject.com/KB/cs/Rumorous_Developer.aspx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.