Hacker News new | ask | show | jobs
by mrtranscendence 1595 days ago
Sometimes it takes code like this:

foo = (

    spark

    .read

    .parquet(...)

    .filter(...)

    .withColumn(...)
)

and turns it into

foo = spark.read.parquet(

    ...
).filter(

    ...
).withColumn(

    ...
)

which feels harder to parse for me. I also never quite got on board with the trailing commas.

2 comments

Actually, modern versions of black will retain the fluent style you prefer, though it will collapse up to the first method call on the first line within the parens, so you end up with something like:

    foo = (
        spark.read.parquet(...)
        .filter(...)
        .withColumn(...)
    )
Personally I prefer my code to read more like a sentence

instead

of

being

split

up

into

too

many

lines.

I guess the point of the parent applies when the parameter lists are long, thus breaking the sentence-like appearance of the chained calls.
These examples remind me why Elixir's pipe operator is so beloved.