Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's a bizarre statement, because chaining leads to shorter lines because each call can gets its own line and there are fewer assignments.



In many (most?) languages chaining leads to longer lines unless programmer makes an extra effor to break them. Compare:

     user = manager.getUser()
     mobile = user.getPhone(PhoneType.mobile)
     area = mobile.getAreaCode()
vs

     area = manager.getUser().getPhone(PhoneType.mobile).getAreaCode()


what about...

    area = manager
           .getUser()
           .getPhone(PhoneType.mobile)
           .getAreaCode();
I see this form a lot in Java and Kotlin code, especially in Kotlin where a single function is just assigned to a chain of functions like the one above.


Good example and exactly what I meant. Having each call on its own line doesn’t solve anything if you also nest the calls.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: