Hacker Newsnew | past | comments | ask | show | jobs | submit | nxpnsv's commentslogin

I don't know if

   result = (df
      .pipe(fun1, arg1=1)
      .pipe(fun2, arg2=2)
   )
is much less readable than

   result <- df |> 
      fun1(., arg1=1) |> 
      fun2(., arg2=2)
but I guess the R thing also works beyond dataframes which is pretty cool

The pipe operator uses what comes before as the first argument of the function. This means in R it would be:

    result <- df
      |> fun1(arg1=1)
      |> fun2(arg2=2)
Python doesn't have a pipe operator, but if it did it would have similar syntax:

    result = df
      |> fun1(arg1=1)
      |> fun2(arg2=2)
In existing Python, this might look something like:

    result = pipe(df, [
      (fun1, 1),
      (fun2, 2)
    ])
(Implementing `pipe` would be fun, but I'll leave it as an exercise for the reader.)

Edit: Realized my last example won't work with named arguments like you've given. You'd need a function for that, which start looking awful similar to what you've written:

    result = pipe(df, [
      step(fun1, arg1=1),
      step(fun2, arg2=2)
    ])

>Implementing `pipe` would be fun, but I'll leave it as an exercise for the reader.

I like exercise:

https://gist.github.com/stuarteberg/6bcbe3feb7fba4dc2574a989...


Neat!

Python supports a syntax like your first example by implementing the appropriate magic method for the desired operator and starting the chain with that special object. For example, using just a single pipe: https://flexiple.com/python/python-pipeline-operator

The functions with extra arguments could be curried, or done ad-hoc like lambda v: fun1(v, arg1=1)


I find this (hypothetical) syntax *very* elegant.

    result = df
      |> fun1(arg1=1)
      |> fun2(arg2=2)

Thanks!

I haven't used R in forever, but is your `.` placeholder actually necessary? From my recollection of pipe operator the value being pipe piped is automatically as the first argument to the next function. That may have been a different implementation of a pipe operator though.

Probably not, I didn’t use R much during the last decade …

Coffee specific scales typically are around 0.1g accurate. They are a little more expensive, but certainly not unobtainable.

I think it mostly isn’t great amounts…

As a swedish parent i see most parents still restrict kids candy only on Saturday. And parents rarely give their kids sodas and never vapes. Perhaps my observation would differ if my kids were in their later teens…

However, in the first case you learned something which probably is useful when you want to change said app in any way or make another project...


Depends on how you learn.

For me it's 50-50 reading other people's code and getting a feel for the patterns and actually writing the code.


Rant: I hate brainstorming meetings. A manager who wants to feel like they are doing something invite a mix of one or two experts, a clueless pm, engineers from an unrelated project, and handful of random ones hers. Next, with zero preparation we’re supposed to come up with groundbreaking new ideas. Then there is some voting and finally waiting for a summary or gameplay that’s postponed until the heat death of the universe. Perhaps I will bring cookies next time.


I actually enjoy brainstorming meetings in-person. These actually feel like a "brainstorm" when they're done right.

Brainstorming meetings over Zoom, on the other hand...


Ah yes, my hate is mostly for the kind of thing that happens on teams/miro.


Sounds like a very poorly run brainstorming session.

How to do it right (IMHO): Have several short but rambling hallway conversations about the upcoming topic for 3-4 days before. Take long showers and let your mind wander. Then do the brainstorming session.


BM is getting rarer on the shelves in Austria. When it first showed up, it was something special, but now there are heaps of great other alternative meats, often cheaper and made here. I guess BM is struggling because of increased competition. During my 20 years of plant based dieat it has never been easier to find fancy plant based things.


Yeah, there is a camp of people who see headlines like this and (giddily) think it spells the demise of plant-based alternatives, probably because since they don't shop plant-based products, their mental concept is stuck 15 years ago where BM was new and experimental, so now they think "heh, not surprised that flopped and we can move on".

But what they don't get is that the market has exploded with competition. Even grocery stores in places like Houston have gone from a couple shelves of vegan products to half-aisles or full-aisles of plant-based food.

Beyond Meat might die in spite of the success of the market it entered into or helped create.


The {} syntax is better, and more similar to f-strings. And you don't have to use that backtrace. I use it to send json for some batch jobs, or have it write to google cloud logger for gcp jobs. Are you holding it wrong?


It's totally subjective that it is better. It's not like it can "execute code" inline like f-string. Just the replacement character is the same, end of the comparison. And any way the point is that more that it totally breaks the general convention for no valid reason. It's not even optional.

For gcp jobs you can just output the structured log in the standard output so I don't see the purpose here. There are other structured logging libraries if this is what you need.

For the backtrace yes, because logging.exception will be broken by default and all tools that process the backtrace automatically like sentry. And again, for no valid reason except than "look, my traceback looks so much cooler on my screen because I added crap and new lines when printing it"...


I don’t care too much about % vs {} . I have stuff where i need nice logs locally, and structured logs in batch, for me loguru made that easy. I don’t think it’s a terrible thing at all, but you do you :)


It looks great out of the box, has fancy colors (if you want them). It is easier to configure than logging and you don't need a lot go get_logger stuff. It does log rotation, and you has lazy formatted {} comments `logger.info("x={x:.2f}", x)`. It is better for threading/multiproc, handles exceptions better. And it is fast. I like it on appearance.


Well if you use loguru (and really you should, it is awesome) you would use, `logger.info("Super log {var}", var=var)` (possibly without the keys). It is also lazy and works better for structured logs.


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

Search: