Coder Social home page Coder Social logo

Code style - chain calls about form HOT 15 CLOSED

yiisoft avatar yiisoft commented on June 12, 2024
Code style - chain calls

from form.

Comments (15)

samdark avatar samdark commented on June 12, 2024 2

Done: https://github.com/yiisoft/docs/blob/master/010-code-style.md#chain-calls

from form.

arogachev avatar arogachev commented on June 12, 2024 1

Great. 👍 But @rustamwin and @darkdef have different opinion. 🤔 Maybe wait for them to share it to avoid extra work.

from form.

vjik avatar vjik commented on June 12, 2024 1

String length included all symbols (including prefix spaces).

from form.

vjik avatar vjik commented on June 12, 2024

Or so:

$this->assertFalse(
    $validator 
        ->validate($formModel) 
        ->isValid()
); 

from form.

arogachev avatar arogachev commented on June 12, 2024

@sankaest Do you want to do it and have time for this?

from form.

sankaest avatar sankaest commented on June 12, 2024

no problem, I'll do (will check all packages again) it by the end of this week :)

from form.

sankaest avatar sankaest commented on June 12, 2024

Any clues for me regarding style? What exactly should be changed and examples (from->to). @arogachev @rustamwin @darkdef

from form.

darkdef avatar darkdef commented on June 12, 2024

I think that reading one line of 80 characters is easier than winding two screens.
Nobody writes like this:

function tttt(
string $str
) {

from form.

sankaest avatar sankaest commented on June 12, 2024

@darkdef could you please copy here "bad" code style (real example, or give row number in the class) and how it should be restyled. It is always better to show how it should be, otherwise guessing a numbers with lottery will be easier, than writing a code what is good enough. :)

And is your example regarding chaining?

Also, @samdark should it be advised in some docs and/or accepted by the community?

I am confused right now, what is "correct" style.

from form.

darkdef avatar darkdef commented on June 12, 2024

Fo example:

example1

$this->getQuoter()->quoteTableName($table)

Vs example2

$this
   ->getQuoter()
   ->quoteTableName($table)

For me - example1 better.
And readable for human.
Example2 by codestyle, but better for pc (it's my opinion)

from form.

samdark avatar samdark commented on June 12, 2024

Yes, it should be documented. Main rules are:

  1. If it is a long chain that doesn't fit line length (120 characters) then each call should on a new line.
  2. It is is a short chain, it is alright to leave it as is.

from form.

sankaest avatar sankaest commented on June 12, 2024

that 120 characters is something new for me (is it final decision?) . In which yiisoft/docs/blob/master/*.md file is (or should this be) mentioned? At least I could not discover it. Need to create new one?

It seems to me, that there is quite a lot of different situations, so examples in *.md should help and clarify.

from form.

samdark avatar samdark commented on June 12, 2024

https://github.com/yiisoft/docs/blob/master/010-code-style.md is a good place to mention it. It wasn't written anywhere else yet.

from form.

sankaest avatar sankaest commented on June 12, 2024

@samdark what about such kind of chain? just and example (total length > 120 char).

$this->chain->withChain()->veryLongChain(['key1' => self::CONST_1, 'key2' => self::VALUE_2, 'key3' => self::CONST_VALUE_3]);

I mean we count length from $this-> till ; with everything inside brackets of chains?
Without inside brackets it would be less, than 120 chars.

$this
    ->chain
    ->withChain()
    ->veryLongChain(['key1' => self::CONST_1, 'key2' => self::VALUE_2, 'key3' => self::CONST_VALUE_3]);

Just to be sure.

from form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.