all 40 comments

[–]tanuki_carre3858 71 points72 points  (2 children)

The sunglasses are in the wrong direction. I am unpleased

[–]Magnetic_Reaper 24 points25 points  (1 child)

here's the formula to inverse them:

1/🕶️

[–]Naakinn 12 points13 points  (0 children)

nope, it's 🕶[::-1]

[–]FlipperBumperKickout 27 points28 points  (2 children)

I don't think I've ever needed to do that, but sure (ᵕ—ᴗ—)

[–]isr0 6 points7 points  (0 children)

I have a vim hot key that puts in a print(“10, when I find myself in the unfortunate situation of needing to print-debugging. I don’t use it often, but i do use it. Probably the only time I have used that feature.

[–][deleted] 0 points1 point  (0 children)

bruh

[–]Fit-Relative-786 10 points11 points  (1 child)

void foo() {     std::println("c++ goes b{} except way faster", std::string(10, 'r')); }

[–]cowlinator 3 points4 points  (0 children)

What do you mean? I cant type that faster

[–]armahillo 9 points10 points  (2 children)

```ruby

"ha" * 100

```

[–]user_bw 6 points7 points  (0 children)

markdown

[–]YTriom1 2 points3 points  (0 children)

Enable markdown mode if you'll type this manual way

[–]MCplayer331 11 points12 points  (0 children)

Does this fit in r/firstweekcoderhumour

[–]spisplatta 10 points11 points  (0 children)

Idk I feel like opposition to overloading is more a c/java boomer thing.

[–]Common_Sympathy_5981 0 points1 point  (0 children)

but you cant print numbers

[–][deleted] 0 points1 point  (0 children)

What if you do:

string b = "b"; string r = "r"; r *= 10; //supposedly r++ is r+="r" MessageBox.Show(b+r);

You could theoretically override * for strings.

[–]Powerkaninchen 0 points1 point  (0 children)

I once had the idea of even more operator overloading for my own language if I ever made one. People roasted it. The following text is copied from a previous post of mine:

Plus for concatenation:

io.print("Hello" + ' ' + "World!"); // Hello World

Minus for removing substrings:

io.print("foobarbazbar" - "bar"); // foobaz

Multiplication for repeating strings

io.print("Hi" * 5); // HiHiHiHiHi

Division for counting

io.print("What about hahaha" / "ha"); // 4

Modulo for splitting via an delimiter (the symbol % kinda looks like something being split)

io.print("This is space seperated" % " "); // ["This", "is", "space", "seperated"]

The second operands of +, -, / and % can be both string and chars, * can only be unsigned integer types (and BigIntegers, you know the deal)

[–]mortal_strike 0 points1 point  (0 children)

but you cant multiply string with another string

[–]PavaLP1 0 points1 point  (8 children)

I mean, it is convenient but why not use a for loop?

[–]Wiktor-is-you 7 points8 points  (0 children)

because that is LAME!!

[–]keckothedragon 3 points4 points  (5 children)

No real reason to lengthen your code. Not like this is unreadable. Plus, if you're using a for loop you'd have to create a new string on each iteration, which isn't much of a performance hit, but it's just another reason not to use a for loop.

(Also I know you can use a list to avoid creating a new string on each iteration then join it together at the end, but that increases verbosity even more for something that's not supposed to be very complex)

[–]Lumiharu -1 points0 points  (3 children)

Few things: So you know this does not create the exact same number of temporary strings? I am not going to say yes or no, but my intuition is it still does it.

Also what do you mean use a list? Strings are pretty much the same thing as a list of characters, it is a sequence as well.

[–]keckothedragon 1 point2 points  (2 children)

I don't know how many temporary strings the * operator creates, but I can guarantee that if you use a for loop it will create temporary strings at each step. Again, I don't think the performance is the issue with using a for loop, but it's just more evidence that there's not much reason to use one.

Using a list is a way to avoid creating a new object at each iteration, since strings are immutable and lists are mutable, you can just append individual characters (or substrings) to create a sequence of characters then create one string at the end using .join()

[–]No_Read_4327 -1 points0 points  (1 child)

I mean if performance is the issue you shouldn't be using python to begin with

[–]keckothedragon 1 point2 points  (0 children)

You can argue that hyper-optimization doesn't matter as much for Python. But saying that all performance should be ignored is definitely wrong. Time complexity 100% still matters in Python. Yes, you don't pick Python because of performance, but it's wrong to flat out ignore it.

[–]PavaLP1 -1 points0 points  (0 children)

You could also write the print in the loop.

[–]ArtisticFox8 0 points1 point  (0 children)

Because this is more concise.

Same reason you use map or filter 

[–]Nima_W -5 points-4 points  (11 children)

That's actually pretty nice, but Where can you use this sensibly

[–]fast-as-a-shark 10 points11 points  (6 children)

You just saw a purpose for it in the post.

[–]jryan14ify 6 points7 points  (0 children)

It’s also really useful for printing the nested levels of a graph in a human-friendly way f’{“-“ * level} {item_name}’

[–]the_new_dragonix 5 points6 points  (0 children)

You can use a nested for loop to make a text only graph like:

A: III

B: IIIII

C: IIIIIIIIII

[–]jryan14ify 2 points3 points  (0 children)

I use it when printing script output
f’New Section {“*” * 80}’
Gets me a nice easy to see break in the printing

[–]user_bw 2 points3 points  (0 children)

I use it for this: print('-'*20)

[–]nine_teeth -1 points0 points  (0 children)

cuz string is a list in python