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

If you cram a lot of formulas, images and graphs into a world document, you'll have an instable slug to work with.

Also, rendering a beautiful word document is quite chalenge.

Rendered latex document looks stunningly clean and professional out of the box.

They also are plain text, which mean they can be diffed, used with git indexed easily, etc. They play well with anything, being text.

You can even read them without having to render them.

And finally, latex check the structure of your doc. If you change it, it will crash, preventing you from commiting dead references.


I always wondered the opposite: how do researchers can get any work done when they have to formalize it using LateX?

I've tried writting a book using LateX, and it's been nothing but a miserable experience. I'm been coding for 15 years, and tweaking my Linux machine for longer. I know what it means to face rought edges.

But LaTeX is another level of shenanigans.

I seem to understand that researchers use latex because of the seemingless formula integration and automation of references.

Well, why not use asciidoc (https://asciidoctor.org/docs/user-manual/#mathematical-expre...) or myst (https://myst-parser.readthedocs.io/en/latest/using/syntax.ht...) then? They are an order of magnitude easier to use, they can generate websites and pdf, use markdown but allow extensions, they support references, and accept latex formulas.

Is it a case of "everybody uses it so I have to"?


Network effects have a lot to do with it. Conferences will give you style files that only work with Latex, and some require the .tex sources when you submit your article.


We have coroutines for that: it delegates any blocking behavior to outside of your code.

Introducing a new paradigm while this one just got in would be overkill IMO.


That's why a lot of functional language research is moving towards effect handlers, which could be explained in a nutshell as "coroutines, but for anything"


How about writting modern and proper Python first? Not to mention designing a decent API?

Let's examine the README example for a minute:

    user: Optional[User]

    if user is not None:
         balance = user.get_balance()
         if balance is not None:
             balance_credit = balance.credit_amount()
             if balance_credit is not None and balance_credit > 0:
                 can_buy_stuff = True
    else:
        can_buy_stuff = False
I don't know if it's been deliberatly twisted, but that's not what I would called idiomatic or realistic for a Python program:

- one should probably never reach this part of the code if there is no user. But I'll indulge the author.

- don't put can_buy_stuff in an else close, what's the point?

- using type hints for no reason, but not other modern facilities like the walrus operator?

- do we really want users without a balance? Let's indulge this, but it seems a bad design.

- what's with all those unecessary conditional blocks?

- credit_amount should never be None. It's a Balance object, put a sane default value. But ok, indulging again.

So, you get down to:

    user: Optional[User]   
    can_buy_stuff = False  
    if user and (balance := user.get_balance()): 
       can_buy_stuff = (balance.credit_amount() or 0) > 0  
I don't think the solution the lib offers is superior:

    can_buy_stuff: Maybe[bool] = Maybe.from_value(user).map(  
        lambda real_user: real_user.get_balance(),
    ).map(
        lambda balance: balance.credit_amount(),
    ).map(
        lambda balance_credit: balance_credit > 0,
    )
And that's if we are using the rules of the README, which are not fair.

If we have a well designed API, and we use a function (more testable, and hey, are we doing FP or not ?), then:

    def can_buy_stuff(user: User):  
        if (balance := user.get_balance()):
            return balance.credit_amount() > 0
        return False
Checking the user should not be part of this algo, credit_amount should be 0 if never set. We could even remove return False, I keep it because I like explicitness.

You could even that as a method or raise NoBalance depending of your case.

Bottom line, if you really feel that strongly about None, don't jump on the bazooka to kill this fly, go to https://discuss.python.org and advocate for PEP 505 (None-aware operators): https://www.python.org/dev/peps/pep-0505/

It's been deferred since 2015.

That doesn't mean we should not experiment with other paradigms in Python, and I do think this lib is an interesting experiment, but I don't find it conclusive.


I'd like to know what happens to can_buy_stuff and the rest of the code when user is Not None and balance_credit is -1.


user can't buy stuff and one unfortunate developer will hunt the bug that charged someone with negative credit.


can_buy_stuff is then False.


Which microsoft understood well: those dev tools are popular, but can't make money. Well, they have money and they need to become popular again.

Deal.


But what about a marketplace for APIs?


Maybe that can be implemented via an API. So I can have some code that can dynamically call this API-as-a-marketplace and decide what's the bests shipping API to use, then it would rewrite itself to use that API.

Say goodbye to vendor API lock-in!


That's essentially what RapidAPI and ProgrammableWeb do.


No, and there is nothing hyper modern about it either.

It's a Python stack that solves some problems for a part of the community.


As said in upper comment, use zipapps. Don't ship your entire env in prod.

Deployment then just become:

- build zipapp - upload zipapp - ensure python interpretter - run zipapp

Which is just one more step than go.


Zipapp doesn't support c extensions though? And that is a large chunk of libraries that I use.


It does, if your extensions are provided as wheels. In which case the resulting pyz file will be runnable on any machine using the OS those wheels are compiled for.

Let's try an example with numpy:

    $ py -m venv foo
    $ foo\Scripts\activate
    $ pip install numpy
    $ code hello_numpy.py
    # import numpy as np
    # def main():
    #     print(np.arange(15).reshape(3, 5))
    $ python hello_numpy.py
    [[ 0  1  2  3  4]
    [ 5  6  7  8  9]
    [10 11 12 13 14]]
Now with shiv:

    $ copy hello_numpy.py foo\Lib\site-packages
    $ shiv -e hello_numpy.main --site-packages test\Lib\site-packages\ -o hello_numpy.pyz
    $ python hello_numpy.pyz
    [[ 0  1  2  3  4]
    [ 5  6  7  8  9]
    [10 11 12 13 14]]
So it works fine, but remember:

- it will only run on the system this particular numpy wheel has been designed to run on. In my case cp38-win_amd64.

- it will comes bundle with numpy. Numpy is quite big, which means your hello world pyz will be 14.1 Mo.

- it needs to unzip, so the first run will be slow


Yeah, Shivs work ok. I've run into some stupid issues with the self-extracting directory being have too long path names on Windows and such, so it's not perfect.


Honestly, the best approach should be "sudo apt get pyenv", but it's such a pain to package a program as a deb I undertand many people don't bother.

Beside, curl works on all linux AND on mac.

Saves time.


You don't have to. Use zipapps, this allows you to create a project with as many deps as you want, but use it as if it was a single python module.

It's an official feature (https://docs.python.org/fr/3/library/zipapp.html) that lets Python execute an entire project bundled into a zip file.

If you don't want to create it by hand, use shiv: https://pypi.org/project/shiv/

It's the best of both worlds.


That's really cool! I can't believe I've never come across this, thanks for sharing!


You are not alone. __main__.py in a zip has been supported litterally since Python 2.6 but very few people knew about it. Eventually in 3.5, the zipapp module has been released to make the feature more discoverable, but again it has been mostly ignored.

I think the reason is that something like shiv was missing: it streamlines the process, shows a finish product instead of just telling people "all the thing they can do", and the automatic unzipping solved plenty of problems that you had with alternative like Pex, espacially on windows or with static resources.

So now you have it. Spread the word.


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

Search: