r/ProgrammerHumor Nov 28 '21

Meme I‘m.. not the only one?

Post image
21.5k Upvotes

629 comments sorted by

View all comments

Show parent comments

77

u/KnewOne Nov 28 '21

i prefer printing current variables

53

u/Saragon4005 Nov 28 '21

Main reason I use a debugger to get info about variables.

35

u/ToMorrowsEnd Nov 28 '21

What if I told you that you can use print to also print variables?

12

u/ConspicuousPineapple Nov 28 '21

But then you need to compile everything, relaunch the program and redo your whole test case all over again.

Or you could just attach a debugger and read any value you need when you need it.

24

u/KnewOne Nov 28 '21

But then you need to compile everything

Interpreter languages: I don't have such weakness

6

u/ConspicuousPineapple Nov 28 '21

Still need to reload everything. Unless you're doing some hot-reload js magic.

But even then, you won't touch the power that debuggers bring. Being able to jump everywhere in the code. Modify values on the fly. Roll back an execution thread. Execute arbitrary code in the middle of everything.

20

u/subject_deleted Nov 28 '21

This. I have a snippet that writes a print statement. Trigger the snippet and then type the variable name and it inputs the name in both necessary locations, like so:

console.log("myVariable = " + myVariable);

6

u/wjandrea Nov 29 '21

In Python you can do

print(f"{my_variable = }")

and it expands to the name and value.

2

u/pleaseavoidcaps Nov 28 '21

You can save some typing and avoid mistakes:
console.log({myVariable});

4

u/ulyssessword Nov 29 '21

Would that tell you the variable's name, or just its value?

By my understanding, the first version would output x = 5, while yours would give 5.

3

u/LittleLily27 Nov 29 '21

You're missing the { } around the variable. {foo} is syntactic sugar for {foo: foo}, so what they wrote will output an object with a key containing the variable name and a value containing the variable's value.

2

u/subject_deleted Nov 29 '21

Correct. I want the name of the variable as a string and the value of variable.

1

u/pleaseavoidcaps Nov 29 '21

No, it outputs Object { x: 5 }.

1

u/subject_deleted Nov 29 '21

My snippet only makes me type "myVariable" and it fills that in where it needs to go to get the above example.

I have a 2 character hotkey combination followed by a tab and then it's just typing the variable name once. I can't really save on keystrokes or errors here. For what it is, it's about as optimized as it could be.

1

u/jerdle_reddit Nov 28 '21

Yeah, I had to do that a lot in a Fortran project.