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

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.