V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
offspring
V2EX  ›  iDev

[[xxx alloc] init]要有空格啊魂淡!不要写成[[xxx alloc]init]好么!

  •  
  •   offspring · 2013-07-01 11:42:03 +08:00 · 4839 次点击
    这是一个创建于 3946 天前的主题,其中的信息可能已经有所发展或是发生改变。
    改之前别人做的项目 一水r的[[xxx alloc]init] 其他的消息嵌套还都有空格 就init没有! 强迫症犯了 全改了 还有方法之间不空一行 要不就空很多行 看起来很不爽啊...
    29 条回复    1970-01-01 08:00:00 +08:00
    iYu
        1
    iYu  
       2013-07-01 12:01:15 +08:00
    你需要Uncrustify
    offspring
        2
    offspring  
    OP
       2013-07-01 12:04:39 +08:00
    @iYu 其实xcode应该加个convert to beautified code...
    iYu
        3
    iYu  
       2013-07-01 12:09:20 +08:00
    @offspring 可惜没有啊,代码风格这种事情太多样了。 配置一个Uncrustify花了整整一个周末 block的对齐还是有问题, 只能辅助一下了。XD
    fangzhzh
        4
    fangzhzh  
       2013-07-01 12:11:09 +08:00
    c语言,c++语言, 我以前看到项目的代码里的大括号竟然和if,while在同一行, 比如 if( a>b){ , 就会抓狂, 然后写脚本修改, 结果和项目组的很多人都冲突,很郁闷

    看到竟然用tab, 而不是四个空格, 脚本修改, 然后和很多人冲突,

    看编码是GB2312, 而不是UTF-8, 修改, 然后源代码管理, 显示乱码,

    每一个我不爽的行为, 都花了我的一部分精力(比如一天), 都让项目组所有人付出了代价,比如花时间解决冲突... 或者要面对乱码的commit信息

    现在我感觉, 强迫症真的要改. 有很多更有价值的东西值得浪费生命....
    offspring
        5
    offspring  
    OP
       2013-07-01 12:13:35 +08:00
    @fangzhzh 我的优势是这个项目只有我一个人做 所以可以随便改...
    fangzhzh
        6
    fangzhzh  
       2013-07-01 12:14:22 +08:00
    @offspring 请参考我最后一句 ^_^
    vvii
        7
    vvii  
       2013-07-01 12:16:16 +08:00
    @fangzhzh if while 的大括号在同一行,有什么问题么?
    我们团队的编程规范就是用C style紧凑型的,
    另外有团队是要求不在同一行。这个只要风格一致就好了吧?
    offspring
        8
    offspring  
    OP
       2013-07-01 12:18:36 +08:00
    @fangzhzh 工作一定要开心嘛 对着一个丑的东西肯定不开心啦 我觉得代码的美化对我来说也是很有价值的东西
    bigredapple
        9
    bigredapple  
       2013-07-01 12:23:07 +08:00
    大括号和if,while在同一行, 比如 if( a>b) {

    这是比较好的一种格式啊。
    XDA
        10
    XDA  
       2013-07-01 12:29:33 +08:00
    一直用
    if(xxx) {
    xxx;
    }
    cyberscorpio
        11
    cyberscorpio  
       2013-07-01 13:42:41 +08:00
    楼上某层真是有病啊。
    alexrezit
        12
    alexrezit  
       2013-07-01 14:06:25 +08:00
    看到那种代码我都没心情工作. 大多是一些基础不好又没什么经验的低等程序员写出来的垃圾.
    raptor
        13
    raptor  
       2013-07-01 14:28:30 +08:00
    @fangzhzh 除了GB2312不能忍,其它还可以忍一忍的……
    fangzhzh
        14
    fangzhzh  
       2013-07-01 14:28:46 +08:00
    @vvii 所以说,是强迫症啊, 以前, 我就喜欢全部按我喜欢的格式. 以前看到@XDA 这种,我就抓狂了, 哈哈
    austinchou0126
        15
    austinchou0126  
       2013-07-01 14:30:54 +08:00 via iPhone
    -(void) Function: (NSString*) string;
    这种风格呢
    fangzhzh
        16
    fangzhzh  
       2013-07-01 14:33:05 +08:00
    @raptor 我现在都改了. 按照项目规范来.
    alexrezit
        17
    alexrezit  
       2013-07-01 14:41:40 +08:00 via iPad
    @austinchou0126
    太闹心了...
    nil
        18
    nil  
       2013-07-01 21:08:48 +08:00
    可以全局替换一下 "]init" -> "] init]"
    jjgod
        19
    jjgod  
       2013-07-01 21:38:52 +08:00
    如果嫌 alloc] init] 麻烦,为啥不直接用 new]?
    refresh
        20
    refresh  
       2013-07-01 21:44:47 +08:00
    强迫症是影响效率的原因之一
    offspring
        21
    offspring  
    OP
       2013-07-01 22:06:06 +08:00
    @jjgod 你看到重点了么少年...
    so898
        22
    so898  
       2013-07-01 22:36:39 +08:00
    @jjgod
    New感觉和alloc init还是不一样的……
    我有几个Class的Init方法,在New的时候不会被执行,在alloc init之后就会被执行……
    话说我至今为止还在研究……顺带着strong和weak一起……
    Zhang
        23
    Zhang  
       2013-07-01 22:38:42 +08:00
    韩语里也是宾语+空格+谓语!
    sethverlo
        24
    sethverlo  
       2013-07-01 22:42:56 +08:00
    @fangzhzh 终于看到不喜欢 if (condition){ 的人了……
    Hysteria
        25
    Hysteria  
       2013-07-02 05:57:24 +08:00
    @sethverlo 这种注释起来真心方便= =。
    fly2never
        26
    fly2never  
       2013-07-02 07:22:51 +08:00
    @so898 从语意上讲,new和alloc init是一样的
    xuzhe
        27
    xuzhe  
       2013-07-02 07:38:56 +08:00
    New 不如 alloc init 好的原因:

    1、new doesn't support custom initializers (like initWithString)
    2、alloc-init is more explicit than new

    所以,既然你无法保证代码里全都用 new,一会儿 new 一会儿 alloc 很分裂,不如统一 alloc + init。

    @fly2never @jjgod @so898
    vileer
        28
    vileer  
       2013-07-02 09:56:56 +08:00   ❤️ 1
    @sethverlo {和if while在同一行是java的风格
    dorentus
        29
    dorentus  
       2013-07-02 10:00:25 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2713 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 05:38 · PVG 13:38 · LAX 22:38 · JFK 01:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.