Back

常见的代码质量问题-- 汇总版 

发布时间: 2014-12-23 05:57:00

写代码的原则: 简单,易于沟通。 建议看的书: <<代码之美>>, 以及 <>

# 不要把有意义的变量名 命名成 foo, bar,  例如下面的,改成叫 guide 或者叫 guide_property 比较合适。
foo = Ti.App.Properties.getString("guide")
# 对于coffeescript , 最后一行默认是return , 所以 下面代码的最后一行的 return 是多余的,应该去掉。
back_me = ->
  Ti.App.addEventListener "close_choice", ->
    $.choice_by_self.close()
    return
#这里要把地址写到配置文件中去。 不要写死在代码中
home_competition_update = ->
    get_json("http://106.185.52.66:1111/interface/games")

#刷新三大成指的数据
there_stock_update = ->
    get_market_json('http://hq.sinajs.cn/list=s_sh000001,s_sz399001,s_sz399006')

# 不要使用 “魔法数"  ,把下面的 1, 2 换成有意义的名字。 例如: 
#点击股票行情                  
SHOULD_SHOW_LEFT = 1
go_to_market_view = (e) ->     
    market_view_select(2)   # 改成: market_view_select( SHOULD_SHOW_LEFT)
    market_click_style(2)      
    there_stock_update()  
#视图切换判定方法           
market_view_select = (num) ->  
    switch num
      when 1   # 改成:  when SHOULD_SHOW_LEFT 
        $.id_market_left_view_style.show()
        $.id_market_right_view_style.hide()
      when 2
        $.id_market_left_view_style.hide()
        $.id_market_right_view_style.show()
# 两个不同的方法,要以一个空行来分割。 
go_to_collection = (e) ->
    alert '收藏'
show_message = (e) ->            # 这一行前面要有个空格
    alert '暂无新消息'  
# 文件命名 不清晰,例如:,item_3.coffee 
看不懂这个是什么。。。
# 无内容的文件,把它删掉。 例如: 
titanium 项目中:app/styles 里面的:  buy_detail.tss,  chart_detail.tss ...
rails 项目中 app/helper 里面的也是。

Back