什麼叫做可讀性高的程式

來源:互聯網
上載者:User

標籤:

舉例來說吧。如果要實現使用者登陸限制的功能,需要以下配置:

  1分鐘內單個使用者登入失敗超過3次顯示驗證碼,並且不能超過5次。

最近發現多數公司喜歡使用通用性可序列化的xml設定檔。

<Actions>    <Action>        <name>email</name>        <rules>            <rule>                <name>byIP</name>                <intervalMinutes>1</intervalMinutes>                <limitCount>5</limitCount>                <warningCount>3</warningCount>            </rule>        <rules>    </Action>    <Action>        <name>email</name>        <rules>            <rule>                <name>byEmail</name>                <intervalMinutes>1</intervalMinutes>                <limitCount>5</limitCount>                <warningCount>3</warningCount>            </rule>        <rules>    </Action></Action>

以上配置的好處是通用性強,益於xml序列化。

但是我更偏愛以下方法:

<Action name="email">  <add name="byIP" intervalMinutes="1" limitCount="5" warningCount="3" />  <add name="byEmail" intervalMinutes="1" limitCount="5" warningCount="3" /></Action>

 

我情願多花點時間做設定檔的映射(可使用.net內建的ConfigurationSection來解決),何況也沒有廢太大的勁。。。

 

那種方法更益於管理和維護應該一目瞭然

什麼叫做可讀性高的程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.