• 请不要在回答技术问题时复制粘贴 AI 生成的内容
mantianyu
V2EX  ›  程序员

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

  •  
  •   mantianyu · Apr 9, 2016 · 4049 views
    This topic created in 3873 days ago, the information mentioned may be changed or developed.

    比如说这道题, 其中 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 replies  •  2016-04-10 15:53:41 +08:00
    jmc891205
    jmc891205
    Apr 9, 2016
    1
    哈哈 这样不是还有两个驼峰式的
    强迫症是病啊大兄弟!
    Vernsu
    Vernsu
    Apr 9, 2016
    2
    注释掉的也是驼峰啊
    KiriGiri
    KiriGiri
    Apr 9, 2016
    3
    不喜欢下划线,会弄的名字很长,而且下划线在右上角,用手按过去很麻烦。
    mantianyu
    mantianyu
    OP
    Apr 9, 2016 via Android
    4
    @jmc891205 本来也应该不会有人要求类型定义和宏定义里的东西也必须遵守某种风格呀

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

    @KiriGiri 长确实是真的。。有时候确实我也觉得不好看。。。
    SoloCompany
    SoloCompany
    Apr 10, 2016 via iPhone
    5
    大小写敏感的系统搞什么鬼下划线
    只有数据库设计这些为了能适应大小写不区分的系统的才会考虑使用下划线
    dxwwym
    dxwwym
    Apr 10, 2016 via iPhone
    6
    驼峰第一个字母也大写?
    xpol
    xpol
    Apr 10, 2016 via Android
    7
    @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
    ColinWang
    Apr 10, 2016
    8
    @dxwwym 类名第一个也大写,其他的方法名,变量名第一个小写。
    allan888
    allan888
    Apr 10, 2016
    9
    https://github.com/jieaozhu/leetcode
    再安利一波我目前的解答,都是 java 的。
    之前刷完的计划还是没实现,目前有一百来题了,正在努力填坑。
    allan888
    allan888
    Apr 10, 2016
    10
    @allan888 话说因为我没刷完,所以 fork 我的我都好心的不定期给发了 pull request 。。。
    然而一个接受 pr 的都没有!!
    mantianyu
    mantianyu
    OP
    Apr 10, 2016
    11
    @allan888 共勉~ 我也在努力填坑中
    SuperFashi
    SuperFashi
    Apr 10, 2016 via Android
    12
    奇怪, C/C++难道不是标准驼峰吗,反正我是一直驼峰 hhhh
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2540 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 00:34 · PVG 08:34 · LAX 16:34 · JFK 19:34
    ♥ Do have faith in what you're doing.