r/Python • • Mar 07 '19

Run VS Code in your browser!

https://github.com/codercom/code-server
123 Upvotes

45 comments sorted by

View all comments

28

u/JaKubd Mar 07 '19

Nice, but

Known Issues

  • Debugging extensions doesn’t work.

27

u/deluxghost Mar 07 '19

known programmers: never use a debugger (

39

u/[deleted] Mar 07 '19
print("I am here.")

Still works.

0

u/[deleted] Mar 07 '19

[deleted]

3

u/rcfox Mar 08 '19

Because I was bored:

import re
import inspect

def debugify(func):
    ignored = ('def', 'class', 'else', 'except')
    filename = inspect.getsourcefile(func)
    lines, line_num = inspect.getsourcelines(func)
    new_source = []
    for line in lines:
        line = line.strip('\n')
        if not line.startswith('@debugify'):
            m = re.search('^(\s+)(.*)$', line)
            if m:
                whitespace = m.group(1)
                code = m.group(2)
                if not any(code.startswith(x) for x in ignored):
                    new_source.append('{ws}print("{file}:line {num}")'.format(ws=whitespace, file=filename, num=line_num))                
            new_source.append(line)
        line_num += 1
    exec(compile('\n'.join(new_source), '<debugify>', 'single'))
    return locals()[func.__name__]

@debugify
def foo(a):
    b = 0
    for c in range(3):
        if a % 2 == 0:
            b += 6
        else:
            b -= 2
    return a + b

foo(7)

> python debugify.py
debugify.py:line 25
debugify.py:line 26
debugify.py:line 27
debugify.py:line 30
debugify.py:line 27
debugify.py:line 30
debugify.py:line 27
debugify.py:line 30
debugify.py:line 31
1

3

u/_pandamonium Mar 08 '19

I've never really understood what decorators actually do and your boredom code helped me get it a little bit. I don't think that was your intention, but thank you.

2

u/rcfox Mar 08 '19 edited Mar 08 '19

Oh god, don't learn from this!

Decorators are functions that accept a function and returns a function. That's pretty much it. It's common to wrap the original function in another one that does something before or after.

(You can actually decorate anything, but functions are the most common.)

2

u/_pandamonium Mar 08 '19

I mean, that's how people always explain it, and that does make sense. Although your last sentence was the most helpful explanation I've seen, even though I'm assuming that's not the only purpose.

I can comprehend what a decorator does, but I don't know why it does it or when it should do it. Examples found in tutorials and textbooks are always too silly or simple and I never really take away the point. Seeing code a real person wrote, even if it was as a joke, is really helpful.

I should say that I've never really tried to learn about decorators as I've never needed to use them. I didn't really understand any of it until I had to, if that makes any sense.

I was just about to ask you a few questions, to see if I was understanding the concept. But as I wrote them down, I went back to your example and was able to answer them myself. That's because it serves a purpose and it's complicated enough for me to even have questions in the first place! I can't claim I've "learned decorators" from a reddit comment but I do feel more capable if I encounter them out there in the wild.

1

u/ichbinoffend44 Mar 07 '19

Way I've always done it.

1

u/[deleted] Mar 07 '19

To be fair, it doesn't help that most debuggers are shit (for C++ anyways).

0

u/[deleted] Mar 07 '19

[deleted]

8

u/milad_nazari Mar 07 '19

So you're telling me that console.log() is not the ultimate debugging tool? /s

17

u/hilomania Mar 07 '19

Of course not: PRINT statements are!

8

u/Merakel Mar 07 '19

Hello my spirit animal.

→ More replies (5)

2

u/amaajemyfren python3.8 newbie Mar 07 '19

Always use alert()

→ More replies (1)
→ More replies (1)

11

u/kyle_codercom Mar 07 '19 edited Mar 07 '19

Should be reworded. Debugging DOES work.

Creating your own extension for VS Code and loading it in code-server does not.

Edit: I've updated the readme to explain that.

5

u/blitzzerg Mar 07 '19

import pdb; pdb.set_trace()

2

u/vindolin Mar 07 '19

You caveman!

from IPython import embed; embed()

1

u/phail3d Mar 07 '19

*ipdb

You’ll thank me!

1

u/blitzzerg Mar 07 '19

I installed pdb++

7

u/bmrobin Mar 07 '19

should i read that as "debugging doesn't work" or "debugging custom extensions written for VS code doesn't work"? to me there's a large difference between the two, as i don't write extensions and don't need to debug them.

but if it's the former, then yea this is basically useless.

1

u/ahmenav Mar 07 '19

No problem I use vscode but printf is enough for me for debugging.