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

迫于摸鱼瞎想,大家是代码折行时.放在哪行

  •  
  •   chenyu8674 · Jan 5, 2021 · 6159 views
    This topic created in 1957 days ago, the information mentioned may be changed or developed.
    a.
    b()
    还是
    a
    .b()


    摸鱼中,想了解下
    Supplement 1  ·  Jan 5, 2021
    a
    .
    b()
    的大哥请受我一拜
    53 replies    2021-01-06 13:16:28 +08:00
    crazyorr
        1
    crazyorr  
       Jan 5, 2021
    a.
    mazhiyuan
        2
    mazhiyuan  
       Jan 5, 2021
    a
    .b(),点在前面清晰点
    fengxuejuan
        3
    fengxuejuan  
       Jan 5, 2021
    只会以字母和下划线开头,所以是第二种
    Zatoichi1966
        4
    Zatoichi1966  
       Jan 5, 2021   ❤️ 1
    一般用第二种,
    因为单行注释,第二种注释后,不需要在调整符号位置;如下:
    a
    //.b()
    .c();
    Zatoichi1966
        5
    Zatoichi1966  
       Jan 5, 2021
    第一种也可以,晕;当我扯犊子吧...
    crazyorr
        6
    crazyorr  
       Jan 5, 2021
    @crazyorr 怎么换行啊?按了回车直接发出去了..
    oxromantic
        7
    oxromantic  
       Jan 5, 2021
    @crazyorr shift+enter ...几百年前就有的机制了,电脑上不用 qq 微信换行么..
    codyfeng
        8
    codyfeng  
       Jan 5, 2021 via Android
    第二种,符号放在行首比行尾好看
    3t
        9
    3t  
       Jan 5, 2021
    莫名觉得第一种漂亮
    Vindroid
        10
    Vindroid  
       Jan 5, 2021
    .b() 放行首第一眼就知道这是个连续代码段
    Lin0936
        11
    Lin0936  
       Jan 5, 2021   ❤️ 6
    a
    .
    b()
    forgottencoast
        12
    forgottencoast  
       Jan 5, 2021   ❤️ 1
    @oxromantic
    你们说的啥,不会是在这里留言怎么换行吧?
    PoetAndPoem
        13
    PoetAndPoem  
       Jan 5, 2021
    没看懂楼主说的是啥, 是指 sublime 的 ctrl+shift+ +/- 的那种快捷键
    PoetAndPoem
        14
    PoetAndPoem  
       Jan 5, 2021
    sorry, 记错了, 是 ctrl + shift + [ / ]
    chendy
        15
    chendy  
       Jan 5, 2021
    肯定要放下一行
    如果是不需要的分号的语言,就一个 b() 看着像调用了一个普通方法一样(虽然从缩进上还能看出来
    PoetAndPoem
        16
    PoetAndPoem  
       Jan 5, 2021
    @Vindroid 总算看懂了楼主说的是啥==,我也是这么做的,
    e.g \
    list.steam()
    .map()
    .collect() \

    一般来说,在 java 里,steam 流用到这个的场景比较多,或者 signature 比较长的场景会这样做
    webassembly
        17
    webassembly  
       Jan 5, 2021
    还好我写 go,没有这个烦恼
    PoetAndPoem
        18
    PoetAndPoem  
       Jan 5, 2021
    @webassembly 给一个示例,求你了
    webassembly
        19
    webassembly  
       Jan 5, 2021
    @PoetAndPoem #18 go 里面只能是同一行或者
    a.
    b() 这种写法
    a
    .b()这样写法会报语法错误
    lithbitren
        20
    lithbitren  
       Jan 5, 2021
    Go 放后面,其他语言原则上放前面。。
    Pastsong
        21
    Pastsong  
       Jan 5, 2021   ❤️ 1
    someStream()
    .pipe(fn)
    .pipe(fn)
    .pipe(fn)
    .pipe(fn);
    iceneet
        22
    iceneet  
       Jan 5, 2021
    a.
    b()
    boris93
        23
    boris93  
       Jan 5, 2021 via Android
    a
    .b()
    .c();
    Pastsong
        24
    Pastsong  
       Jan 5, 2021
    @Pastsong v2 会 trim 掉行首空字符...上面的.pipe 前面有个 tab 缩进的
    wr516516
        25
    wr516516  
       Jan 5, 2021
    a
    .b()
    .c();
    favourstreet
        26
    favourstreet  
       Jan 5, 2021 via Android
    写.b()
    放上一行看起来不像句号吗?
    oxromantic
        27
    oxromantic  
       Jan 5, 2021
    .b()

    除了上面的 go,用 IDE 应该都这种形式吧,毕竟"."会触发方法提示,在触发方法提示的时候敲个回车不是为难自己么
    icyalala
        29
    icyalala  
       Jan 5, 2021
    @icyalala 错了。。是 JS 。。
    b00tyhunt3r
        30
    b00tyhunt3r  
       Jan 5, 2021
    @Pastsong
    这功能非常 annoying
    说实话 v2 有不少自作聪明实则鸡肋的冗余功能
    真正有需求又体现实力的地方比如传图,传视频又做不好
    Leviathann
        31
    Leviathann  
       Jan 5, 2021 via iPhone
    现代 ide 和 lsp 都有链式调用换行时在行尾自动添加类型提示信息的功能
    所以肯定是点在前面啦
    qwerthhusn
        32
    qwerthhusn  
       Jan 5, 2021   ❤️ 1
    其实我想考虑的是
    "abc"
    + "def"
    还是
    "abc" +
    "def"
    bog
        33
    bog  
       Jan 5, 2021 via Android
    交给 clang-format 吧,否则一个团队内总会有不一样的声音的
    en20
        34
    en20  
       Jan 5, 2021 via iPhone
    放第一行尾如果太长,会让第二行看起来是函数定义,不要这样
    joesonw
        35
    joesonw  
       Jan 5, 2021
    a
    .b()

    新增 .c() 的时候只有一行 diff
    zhangshine
        36
    zhangshine  
       Jan 5, 2021
    a
    .b()

    第二行多点空格🤣
    waynnne
        37
    waynnne  
       Jan 5, 2021
    a
    .b()

    Java 的 Stream 流、Builder 模式中比较常见。
    dream7758522
        38
    dream7758522  
       Jan 5, 2021 via Android
    a.b
    dream7758522
        39
    dream7758522  
       Jan 5, 2021 via Android
    a.b
    ()
    linux40
        40
    linux40  
       Jan 5, 2021 via Android
    不知道,我从没想过这个问题,我都是用代码自动格式化工具来折行的。
    palfortime
        41
    palfortime  
       Jan 5, 2021 via Android
    交给 rustfmt 烦恼
    jzmws
        42
    jzmws  
       Jan 5, 2021
    @Lin0936 你们公司按照代码行算工资吧
    a
    .
    (
    )
    jzmws
        43
    jzmws  
       Jan 5, 2021
    不过一般是

    a
    .b()

    很多开源的都是按照这样写的,然后我也用

    其实跟多 a.b(c-{
    })
    no1xsyzy
        44
    no1xsyzy  
       Jan 5, 2021
    @qwerthhusn C 、Python 等语言可以不用加号,实际被当作一个完整的字符串字面量:
    "abc" \
    "def"
    或者,在不产生歧义的情况下可以不加反斜杠
    ("abc"
    "def")
    dotw2x
        45
    dotw2x  
       Jan 5, 2021 via iPhone
    习惯这么搞,看着爽一点
    list.Where()
    .Take()
    .Select()
    .ToList();
    ychost
        46
    ychost  
       Jan 5, 2021
    stream().map(..)
    .filter(..)
    .reduce(..)
    20015jjw
        47
    20015jjw  
       Jan 6, 2021 via iPhone
    不同语言不一样吧...
    PEAL
        48
    PEAL  
       Jan 6, 2021
    突然想起来 layui 的窒息写法

    table.render({
    elem: '#demo'
    ,height: 312
    ,url: '/demo/table/user/' //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
    {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
    ,{field: 'username', title: '用户名', width:80}
    ,{field: 'sex', title: '性别', width:80, sort: true}
    ,{field: 'city', title: '城市', width:80}
    ,{field: 'sign', title: '签名', width: 177}
    ,{field: 'experience', title: '积分', width: 80, sort: true}
    ,{field: 'score', title: '评分', width: 80, sort: true}
    ,{field: 'classify', title: '职业', width: 80}
    ,{field: 'wealth', title: '财富', width: 135, sort: true}
    ]]
    });
    gaigechunfeng
        49
    gaigechunfeng  
       Jan 6, 2021
    这,上,热,门?
    哈哈,年底池塘的鱼都不够摸了吗
    songco
        50
    songco  
       Jan 6, 2021
    都能接受, 项目统一的 formatter 是什么样就按什么来
    togou
        51
    togou  
       Jan 6, 2021
    Pms
    .then()
    .then()
    这也太标准了啊
    短的直接
    [].filter().map().some();
    yamasa
        52
    yamasa  
       Jan 6, 2021
    Java 要是写 stream lamda 或者 reactive,不用.func()太难看了啊。 一行一行的.func()感觉足够优雅,可读性也好得多。
    wangyzj
        53
    wangyzj  
       Jan 6, 2021
    除了 js
    用前者
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1460 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 110ms · UTC 17:00 · PVG 01:00 · LAX 10:00 · JFK 13:00
    ♥ Do have faith in what you're doing.