The thread formerly known as "Weekend Coding"

Today I learned

>>> from __future__ import braces

SyntaxError: not a chance

I been doing some more programming lately, and on a whim I decided to try out that VSCode that everyone loves so much. Itā€™s free, and I can just uninstall it. TL;DR: Went relatively smoothly. Was impressed by some things. But then a tiny problem reminded me why IDEs can all burn in hell, and Iā€™m uninstalling that trash.

So I install it. And for a test spin I figure I will try out its supposed WSL integration.

It just worked! Impressive!

Oh right. Itā€™s not vim. I know there are ways to make it vim style.

BOOM. Just works! Amazing. VSCode is basically unchanged except for the fact that the text editor boxes control like vim. Basically perfect. I noticed no meaningful difference compared to actual vim when typing.

Ok, off to a good start, how about that Python integration. I point it at my advent of code repo, and it does its Python thing. Not too bad!

Ok, letā€™s push the play button on one of my advent of code problems to test it out. Letā€™s try the first part of 2020 day 1.

apreche:~/projects/advent-of-code [main *%] $ /usr/bin/python /home/apreche/projects/advent-of-code/2020/01/find_2020-1.py
Traceback (most recent call last):
  File "/home/apreche/projects/advent-of-code/2020/01/find_2020-1.py", line 26, in <module>
    values = file_to_int_list('input.txt')
  File "/home/apreche/projects/advent-of-code/2020/01/find_2020-1.py", line 9, in file_to_int_list
    with open(filename) as input_file:
FileNotFoundError: [Errno 2] No such file or directory: 'input.txt'

Oh, I see whatā€™s happening. Itā€™s running the python executable from the top of the project, instead of from the directory where the file is located. Simple enough. Letā€™s google on how to get VSCode to change that behavior.

Aha! We have to change something in the launch.json. Perfectly reasonable. We have to at least provide some amount of configuration to tell VSCode how to execute our app when we press the play button. Every project is different. The launch.json file seems very simple and reasonable. I make the change as directed by the StackOverflow answer with 151 points.

It doesnā€™t work. Did I type it wrong? Nope. Oh, I didnā€™t save the changes to launch.json. Still doesnā€™t work. Maybe I have to reload the project or restart VSCode? Nope, still doesnā€™t work. This setting does nothing. The cwd is not changing in any way whatsoever.

Let me Google for more answers.

Ok, so thereā€™s a checkbox buried in some settings menu. Why is this setting in data science? What does it have to do with data science? I donā€™t even have a data science in preferences. Ok, it seems the preferences at least has a search function. Aha! I found the setting. They moved it to Python > Terminal > Execute In File Dir which makes a lot more sense actually. I check the box, and it works.

But even though it works, itā€™s not really what I want. This is a global setting applying to all projects. The launch.json is project specific settings. I can imagine a lot of cases where I donā€™t want to change the cwd for a project, but now I have to change this global setting every time I change projects?

And if this kind of thing happened and took me 10 minutes to figure out on just the simplest advent of code Python script, what kind of hell am I going to encounter if I try to work on an actual complex project?

You know how you change the directory in a good old terminal? cd /the/fucking/directory DONE.

Even after how many years of IDEs existing, and improving dramatically, I still just canā€™t fucking deal with it. Itā€™s enough work to make my code correct. I do not have time for patience for anything that causes my code to not work that isnā€™t a flaw in the code itself. I donā€™t have one spare second of time or patience to spend on solving problems caused by the IDE, so in the trash it goes.

Back to the trusty old text editor and terminal. Maybe Iā€™ll give IDEs a chance again in 2030.

For what itā€™s worth, Pycharm handles working directories the way you would expect, i.e. on a per-run-config basis.

I know a lot of people like VS code, but every time I try to use some Microsoft tool, I feel like I run into insane issues.

WSL seems to be the exception. Maybe because itā€™s just straight-up Linux.

My co-workers use PyCharm. I havenā€™t tried it in many years, but I had similar problems with it way back when I did try it. Iā€™m sure itā€™s possible to make it work, since I do see co-workers using it on the exact same projects Iā€™m working on. Iā€™m sure even if I had trouble, I could ask them and be all set up.

But why? Been using bash/vim for how many years. The co-workers using IDEs who are better at programming than I am arenā€™t better because of their IDEs. They would still be better than me if they had to use Notepad.

But yeah, Iā€™ve tried many many over the years going back to Borland stuff in the '90s. I think the only time I had a great experience with no issues was with whatever Visual Studio was newest in '98-'99, but I only used it for Visual Basic in school.

Of the many Iā€™ve used on so many platforms ranging over the past 20+ years there was almost always some problem where my perfectly correct code, that compiled/ran perfectly in the terminal, would not run perfectly in an IDE when I pressed the play button. To this day I get so angry when that happens, that I think itā€™s probably best I give IDEs another 10 years before I give them another shot.

I use Pycharm for all my python coding, and also couldnā€™t work out what issues you were having with the other IDE because Pycharm just works as I think it should running different scripts in different projects.

The last time I tried it, who knows how many years ago, I remember only the following.

I installed it. I started a new project. I wrote a hello world script like print "hello". I donā€™t think python 3 existed then, so it wasnā€™t print("hello"). I pressed the play button that should have executed the script. It made some kind of error. I went to the terminal and used normal python on the saved .py file and it ran, proving the code was correct. I uninstalled PyCharm and never bothered to try it again.

Iā€™m so glad Iā€™m not so picky.

1 Like

I donā€™t see how preferring thing that works vs. thing that does not work is being picky.

Iā€™ll also sing the praises of jetbrains (the company that makes pycharm) and their IDEs, Iā€™ve used a ton of different languages in the last 5 years and their IDEs are the best of the bunch.

Also, dude, python3 was released twelve years ago, pycharm in 2010 some time, Iā€™m going to go out on a limb and say that itā€™s probably fixed a few things in the interim. Not that Iā€™m sure itā€™ll work for you, Iā€™ve got a hunch that because youā€™re not familiar with IDEs thereā€™s something in the set up that youā€™re missing that the rest of us are taking for granted.

I started programming back in the late 80s as a kid and programmed with everything from vim and bash (even recently, I still use them) to all the modern IDEs. Use whatever you want to use. They all work.

If you are willing to open your heart and actually consider the possibilities, you can click on this.

For me, Iā€™d probably say thereā€™s two* major pluses.

One

Thereā€™s a flood of small, useful features. I know an expert vimsman could find a plugin for some of it. But I bet not all. Thereā€™s a lot!

Things like live-grep across the whole project.
Both-sides editable diff window between files. Or a git revision. Or the currently highlighted text. Or the clipboard.
The little colors in the gutter that show where a file has had lines edited, added, deleted.
Jump to the declaration of this variable.
Find all the usages of this variable across the whole project.
Rename this function and all its usages.

Thereā€™s so many things like that.

Two

The debugger. Do you use pdb? Itā€™s honestly like night and day. The ability to debug django templates jumps to mind, but itā€™s not really a comparable experience.

I think if you gave it a fair shot, you would find itā€™s really nice.

Otherwise if youā€™re just going to be an old grump, catch you in 2030.

I feel like I have all those features you listed already, and my vim has far fewer plugins and customizations than almost any other vim people I know.

Also, I use ipdb, not pdb. I recently learned about PEP 553. Not only did it make inserting breakpoints easier, but it made it possible to configure ipdb, or any other debugger, as global default.

I didnā€™t know about breakpoint(), that is nice.

How are you setting breakpoints in Django templates??

At work we donā€™t even use django templates. We just return JSON and the front-end is all Javascript/React.

I also do use the werkzeug in-browser interactive debugger on my local Django runserver with runserver_plus. It doesnā€™t interactively debug templates, but it is still very helpful with all errors, including template errors.

For stuff like frontrowcrew.com the django templates are so ridiculously simple that no code in the template would ever need to be interactively debugged. If I find myself needing a complex structure in a template, I write a custom template tag. That puts the code back into Python where I can use ipdb/werkzeug. If the problem in the template is HTML/JS related I press F12 in Firefox. I think itā€™s F12 in Chrome as well.

In my question to make apps using Borland TurboVision Iā€™m (re)learning C++ from a very good book called C++ Primer. Very good book for someone who already knows how to program, but just wants to learn the syntax and specifics of C++. Only complaint is that a lot of the exercises have ambiguous instructions.

Anyway, I put the (re) in parens above because even though I have written many programs in C++ in the distant past, wow. There is a lot of stuff I did not know, or did not fully comprehend.

My opinion of C++ used to be that it was good for the right use cases, like maybe a game engine. However, it was kinda meh and full of lots of confusing syntax that hurt readability. Too much of the thing::otherthing<whoah really, are you> serious; kinds of stuff that nobody can read.

Now Iā€™m starting to see that most of this stuff is just trying to give you powerful tools for dealing with types. You can get all the benefits of a strictly typed language, but with liberal usage of tools like typedef/using, decltype, etc. you can minimize that sort of stuff and write expressive code that is on the nice level of more modern languages.

At the very least, itā€™s more fun than the programming I get paid to do.

2021 week 1: Bean Dad
Also 2021 week 1: coup

2021 week 2: Scott quits web dev, gets a job embedded programming

And we thought this year was going to be calmer than 2020.

Whoa, python gets a switch statement. And itā€™s on steroids?

Status: Accepted

match command.split():
    case ["go", ("north" | "south" | "east" | "west") as direction]:
        current_room = current_room.neighbor(direction)

    case ["go", _]:
        print("Sorry, you can't go that way")

Iā€™m usually a fan of using a dictionary lookup for this kind of thing, but this seems to be conditionally (lol) better. Time will tell.

That gives me a bad idea.

# normal programmers
if value == 1:
    do_stuff()
elif value == 2:
    etc()
elif value == 3:
    foo()
...


# sickos
branches = {1: do_stuff 2: etc, 3: foo}
branches[value]()
1 Like

I am the sicko. Guilty as charged.

1 Like

Calling functions out of a dict? You madman. I thought you meant like, pulling args out of a dict or something, because who would be that ^ demented.

do_stuff(args_choices[value])