V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
mantianyu
V2EX  ›  程序员

有没有童鞋刷 leetcode 的必须把驼峰式命名改成下划线风格的?

  •  
  •   mantianyu · 2016-04-09 22:49:06 +08:00 · 3138 次点击
    这是一个创建于 2940 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比如说这道题, 其中 Judge 系统给默认定义了如下 struct ListNode 类型.

    /**
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     struct ListNode *next;
     * };
     */
    struct ListNode* removeElements(struct ListNode* head, int val) {
        
    }
    

    作为一个坚守下划线命名风格的 c 程序员, 我是一定要写成下面这样的:

    /**
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     struct ListNode *next;
     * };
     */
    
    #define remove_elements     removeElements
    typedef struct ListNode          list_node;
    
    list_node* remove_elements(list_node* head, int val) {
        
    }
    

    虽然好像变量名字长点的话确实没有驼峰式好看....

    12 条回复    2016-04-10 15:53:41 +08:00
    jmc891205
        1
    jmc891205  
       2016-04-09 22:52:53 +08:00
    哈哈 这样不是还有两个驼峰式的
    强迫症是病啊大兄弟!
    Vernsu
        2
    Vernsu  
       2016-04-09 23:09:34 +08:00
    注释掉的也是驼峰啊
    KiriGiri
        3
    KiriGiri  
       2016-04-09 23:21:27 +08:00
    不喜欢下划线,会弄的名字很长,而且下划线在右上角,用手按过去很麻烦。
    mantianyu
        4
    mantianyu  
    OP
       2016-04-09 23:45:00 +08:00 via Android
    @jmc891205 本来也应该不会有人要求类型定义和宏定义里的东西也必须遵守某种风格呀

    @Vernsu 注释马块懒得改了。。

    @KiriGiri 长确实是真的。。有时候确实我也觉得不好看。。。
    SoloCompany
        5
    SoloCompany  
       2016-04-10 06:07:05 +08:00 via iPhone
    大小写敏感的系统搞什么鬼下划线
    只有数据库设计这些为了能适应大小写不区分的系统的才会考虑使用下划线
    dxwwym
        6
    dxwwym  
       2016-04-10 07:25:21 +08:00 via iPhone
    驼峰第一个字母也大写?
    xpol
        7
    xpol  
       2016-04-10 09:20:43 +08:00 via Android
    @dxwwym Wikipedia:The first letter of a camel case compound word may or may not be capitalized, and there is no real consensus on whether the term camel case generally implies an uppercase or lowercase first letter.[2][3][4] For clarity, this article calls the two alternatives upper camel case and lower camel case. Some people and organizations use the term camel case only for lower camel case.
    ColinWang
        8
    ColinWang  
       2016-04-10 09:51:41 +08:00
    @dxwwym 类名第一个也大写,其他的方法名,变量名第一个小写。
    allan888
        9
    allan888  
       2016-04-10 10:03:41 +08:00
    https://github.com/jieaozhu/leetcode
    再安利一波我目前的解答,都是 java 的。
    之前刷完的计划还是没实现,目前有一百来题了,正在努力填坑。
    allan888
        10
    allan888  
       2016-04-10 10:04:37 +08:00
    @allan888 话说因为我没刷完,所以 fork 我的我都好心的不定期给发了 pull request 。。。
    然而一个接受 pr 的都没有!!
    mantianyu
        11
    mantianyu  
    OP
       2016-04-10 10:10:33 +08:00
    @allan888 共勉~ 我也在努力填坑中
    SuperFashi
        12
    SuperFashi  
       2016-04-10 15:53:41 +08:00 via Android
    奇怪, C/C++难道不是标准驼峰吗,反正我是一直驼峰 hhhh
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5772 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 02:43 · PVG 10:43 · LAX 19:43 · JFK 22:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.