how should I organize my project? (beginner) anthony explains

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 พ.ย. 2024

ความคิดเห็น • 33

  • @_Amilio_
    @_Amilio_ ปีที่แล้ว +12

    "stick with that until it is painful" 👍😂

  • @fexofenadinaGenerica
    @fexofenadinaGenerica ปีที่แล้ว +14

    This is a nice advice. Although I would not bare to have a file with more than 500 lines. But yeah, splitting things when the need arrives is the best way to go

    • @nexovec
      @nexovec ปีที่แล้ว +2

      Largely depends on your stack. I like using as few things as possible and use languages that have compilers, and that enables me to write single file pograms of couple thousand lines. But this is python land, so no :D

    • @nicwhites
      @nicwhites ปีที่แล้ว

      @@nexovec I’d argue your logic should be reversed. Being compiled, you should have better structured projects as once built it will be a single binary (unless you’re build .so ) vs python which being that it’s a runtime language, you’d have to distribute more files in order to run.
      In the end though, the most important thing is actually building something so if it works for ya and you’re building things, then keep it up

    • @nexovec
      @nexovec ปีที่แล้ว

      @@nicwhites The fitting continuation of this conversation is that I've mostly transitioned to go. Bottom line for me is a more structured language leads to more structured code. If your standard for code quality is high enough, python starts to need some help from external tools to get the same thing at best.

  • @ericng8807
    @ericng8807 ปีที่แล้ว +25

    so you're telling me you don't enjoy dedicating 1 file for every class!?!

    • @Bryft
      @Bryft ปีที่แล้ว +5

      _smiles in java_

  • @santiagoperez6769
    @santiagoperez6769 3 หลายเดือนก่อน

    Love the channel! I swear I go through this everytime and endup starting projects way too late lol. Question, how would you go about setting up a project that uses different python versions? For example, I have a project that requires python2.7 and python3.9. Its a drone project and its essentially 2 scripts, one for each python version. The scripts will be executed sequentially, so first the 3.9 script and then the 2.7 script. However, I am not sure if its better to use virtual environments or docker... any insight will be greatly appreciated. Thanks!

    • @anthonywritescode
      @anthonywritescode  3 หลายเดือนก่อน +1

      I would port the 2.7 code to python 3, it's 4 years end of lifed after all.

    • @santiagoperez6769
      @santiagoperez6769 2 หลายเดือนก่อน

      @@anthonywritescode, thanks for the reply! And yeah, I would love to do that, but that would be a big task since the code communicates with the drone's firmware and I believe there are some physics and PID loop aspects, so I might have to get familiar with the ArduPilot code (the drone autopilot firmware) as well... it's a task that I've never taken on before. lol, But I guess thats more of a reason to dive in, right? lol, The 2.7 code I'm referring to is actually an open-source API, its the dronekit repo, which uses the MAVLink communication protocol to control the drone's autopilot. It requires Python 2.7 and its really unfortunate, but I might go ahead and try to port it myself so that I have it for future use and to contribute to the open-source project. Have you ever taken on such a task? If so, any good resources I can read or look up to get me started? Im going to reach out to the authors of the API as well, but to start, I was thinking that drawing out a giant flowchart or something to visualize the mechanics would be good. Something to wrap my head around the big picture

  • @Ca1vema
    @Ca1vema ปีที่แล้ว +4

    At work we have main application file which contains 31k SLOC and no open source language server can handle this, have to use py charm if one want to use some fancy lsp features. Split your file guys :(

    • @d3stinYwOw
      @d3stinYwOw ปีที่แล้ว

      PyCharm doesn't choke on it? Maybe try different IDE :P

    • @Ca1vema
      @Ca1vema ปีที่แล้ว

      @@d3stinYwOw which one, for example?

    • @d3stinYwOw
      @d3stinYwOw ปีที่แล้ว

      @@Ca1vema As IDE? If it can be non open source one, wing python ide might also work for this, if PyCharm chokes on this file.

    • @Ca1vema
      @Ca1vema ปีที่แล้ว +2

      @@d3stinYwOw I said pycharm is the only IDE which is able to handle this with fancy language server features… so we have to use it, even if we don’t like it.
      Will try Wing, thanks

    • @d3stinYwOw
      @d3stinYwOw ปีที่แล้ว +1

      @@Ca1vema Sorry, I misunderstood. If you want to use LSP instead of full IDE, I can recommend Kate with pyls/pylsp. How can I replicate your case on my side in order to check if LSP have troubles on files this big?

  • @theendlessriver13
    @theendlessriver13 ปีที่แล้ว +1

    would you go the same way with tests? For tools like pyupgrade tests are always end to end tests and fully independent on the implementation. Although you usually don't want to test implementation, sometimes you test smaller parts individually, but while also having larger end to end tests, which may be slow. Would you split those out or mark them and use something like "-k not slow"?

    • @anthonywritescode
      @anthonywritescode  ปีที่แล้ว +4

      pyupgrade's tests were all in one file too -- and the integration-y tests aren't slower than the unit tests -- pyupgrade's 1000 tests run in like ~500ms. I usually make the testsuite match the project structure

  • @samuelcurrans2506
    @samuelcurrans2506 ปีที่แล้ว +2

    Yo Anthony do you know where you got that shirt it looks fire.

  • @jamesfitzpatrick9607
    @jamesfitzpatrick9607 ปีที่แล้ว

    I like the idea of rhe sungle file but want to add my reasoning for not doing it. Normally when coming back to a project I can't remember what is going on and the new work gets added to a new file while i explore what i am doing. Then this gets refactored as I work more on the feature.
    I am not saying this a good way, only that it is my way.

  • @lukerbs
    @lukerbs 7 หลายเดือนก่อน

    this is definitely a hot take!

  • @ancoopa
    @ancoopa ปีที่แล้ว

    Great thoughts. Thank you for sharing. ^^

  • @walkdead94
    @walkdead94 11 หลายเดือนก่อน

    Or.. bundle whatever you have in a .zip with the __main__.py and it becomes a single file again! :)

    • @anthonywritescode
      @anthonywritescode  11 หลายเดือนก่อน

      that's more of a question of _distributing_ it -- not about organization. also misses the point of this video which is "don't worry about it and start building or you'll never finish"
      also have a video on zipapps here: th-cam.com/video/HfL2s2JySos/w-d-xo.html and how you can make them even more powerful as exes on windows: th-cam.com/video/nzaH5n-Xk64/w-d-xo.html

  • @ItzAnameOk
    @ItzAnameOk ปีที่แล้ว

    Hello hello!

  • @b_0rk
    @b_0rk ปีที่แล้ว +3

    How DARE YOU tell me not to use $PYTHONPATH ... my setup works perfectly for me!!!!

    • @Bryft
      @Bryft ปีที่แล้ว

      Well, if it suits your needs ;-]
      But damn, recently I was playing with Robot Framework and Apache Airflow, and both of them also do some weird shit with PYTHONPATH, so it doesn't seem to be only a rookie mistake. Unfortunately :-/

    • @anthonywritescode
      @anthonywritescode  ปีที่แล้ว +1

      heh griffinbork is being heavily sarcastic :)