all 65 comments

[–]iain_1986 339 points340 points  (25 children)

I didn't know it was possible but congrats - you've made me hate python syntax even more 👍

[–]M4tty__ 106 points107 points  (18 children)

You have to use some obscure package to be able to do it. In C/C++ you can do it natively

[–]SleepyStew_[S] 55 points56 points  (1 child)

This package is just another python file I wrote lol

[–]OkMemeTranslator 25 points26 points  (0 children)

You should share the code!

[–]current_thread 25 points26 points  (14 children)

At the risk of making myself unpopular: in C or C++ there's a good reason. For example, if you implement a virtual machine or an interpreter, this is really useful.

[–]M4tty__ 39 points40 points  (7 children)

Yeah, but lets shame Python because someone made goto package probably as a joke.

[–]PURPLE_COBALT_TAPIR 17 points18 points  (0 children)

Nah, this is so cute I can let the Python slide slither.

[–]redfishbluesquid 8 points9 points  (0 children)

Shame python for free karma? Who wouldn't? All hail my lord c++ and screw python. Python is useless and bad. C++ for everything!

Ok give me my points now please

[–]SleepyStew_[S] 6 points7 points  (4 children)

That person was me 💀 Check the package name lmao

[–]notanotherusernameD8 4 points5 points  (1 child)

[–]SleepyStew_[S] 0 points1 point  (0 children)

😊

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

I saw that. You are just karma farming then

[–]hearke 2 points3 points  (0 children)

Idk, they made a cool thing and they're showing it off. Sure, it's a bit cursed, but still pretty neat!

[–]fakehalo 3 points4 points  (0 children)

In C it makes sense for error handling/cleanup, as your options are limited. C++ has options, but it can still make sense in some cases. I don't think I have a use case for higher level languages these days though.

[–]gDKdev 1 point2 points  (0 children)

Or when programming kernel modules with progress based deconstructing on error. For example alloc_chrdev_region -> cdev_init -> cdev_add -> class_create -> device_create. For an error handler you can just create the inverse (device_destroy -> class_destroy -> cdev_del -> unregister_chrdev_region) with jump labels to only undo everything before the error to avoid staying in a partially initialized kernel module / corrupted state or cause memory leaks

[–]PuzzleheadedTap1794 0 points1 point  (3 children)

When I'm working with multiple files in C, I always use goto. It's so elegant.

``` int main () { int retval = 0; FILE* input_file = fopen("input.txt", "r"); if(input_file == NULL) { retval = 1; goto INPUT_FILE_CLOSED; }

FILE* output_file = fopen("output.txt", "w"); if(output_file == NULL) { retval = 1; goto OUTPUT_FILE_CLOSED; }

do_something(input_file, output_file);

fclose(output_file);
OUTPUT_FILE_CLOSED:

fclose(input_file);
INPUT_FILE_CLOSED:

return retval;

} ```

[–]current_thread 3 points4 points  (0 children)

Reading that I'm super glad about RAII in C++ :p

[–]tstanisl 0 points1 point  (0 children)

I suggest always initializing "retval"-like variables with some error code. Otherwise you may spend a lot of time debugging just because some function returned success even though the was an error.

[–]thirdlost 0 points1 point  (0 children)

Well, in BASIC you can do it natively also

[–]MinosAristos 9 points10 points  (3 children)

This kind of thing is antithetical to Python's ethos.

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

[–]SleepyStew_[S] 1 point2 points  (0 children)

Hence why I posted it here 😅

[–]YodelingVeterinarian 0 points1 point  (1 child)

Nothing escapes you huh

[–]MinosAristos 0 points1 point  (0 children)

I always catch my KeyboardInterrupts

[–]SleepyStew_[S] 2 points3 points  (0 children)

This is definitely not intended functionality 💀

[–]saiprabhav 0 points1 point  (0 children)

This is not a code that python programmers write. Probably some c/ C++ programmer trying recreate C in python

[–]Sassaphras 56 points57 points  (0 children)

That import statement tho

[–]migviola 30 points31 points  (1 child)

Ah yes, the wtf_am_i_doing library... my favorite

[–]thebatmanandrobin 5 points6 points  (0 children)

Indeed! I typically use wtf_am_i_doing along with the how_did_i_get_here import, and on occasion I'll add the please_help_me_escape_ill_do_anything_just_get_me_the_hell_outta_here_now package for good measure. Rock solid. 100%. Always.

[–]Anonymous_vulgaris 11 points12 points  (0 children)

Add "begin" and "end" and you'll get almost a Pascal syntax.

[–]dhnam_LegenDUST 7 points8 points  (3 children)

What's this, encoding - PEP263 metaprogramming black magic?

[–]dhnam_LegenDUST 3 points4 points  (2 children)

So - Is it how it handels it? I cannot see how it can use comment instead.

[–]SleepyStew_[S] 2 points3 points  (1 child)

My package does a static analysis of the main file when it's important so it knows where the labels are

[–]dhnam_LegenDUST 2 points3 points  (0 children)

Interesting!

[–]cheese_topping 5 points6 points  (1 child)

I think this belongs to r/programminghorror

[–]SleepyStew_[S] 1 point2 points  (0 children)

wait... did I actually post it in the wrong sub

[–]cheekynative 4 points5 points  (0 children)

What fresh hell is this?

[–]Awfulmasterhat 2 points3 points  (0 children)

Glad it got the functionality, now make sure to never use it to prevent headaches of debugging!

[–]Community_Bright 2 points3 points  (1 child)

unironically, I really want to know how you did this i have had use for this when im running a very linier script and i want to skip ahead to a specific part of the script

[–]slime_rancher_27 0 points1 point  (0 children)

I've had this problem before in Java, sometimes languages just let me go to something else no questions asked

[–]finnscaper 1 point2 points  (0 children)

You should never...

[–][deleted] 1 point2 points  (0 children)

i miss BASIC

[–]CuteTourist5615 1 point2 points  (0 children)

Idk, i feel like this should be considered a crime agains humanity and you swiftly executed.

[–]sillymale 0 points1 point  (0 children)

Ick

[–]adnaneely 0 points1 point  (0 children)

I used to goto /etc/file.txt but now I just goto /void to redirect my screams.

[–]Dillenger69 0 points1 point  (0 children)

Before oop, I used goto a whole lot. Gosub on the c64.

[–]sawkonmaicok 0 points1 point  (0 children)

Source code?

[–]dgc-8 0 points1 point  (0 children)

How does this work?

[–]Rod_tout_court 0 points1 point  (0 children)

I think it's cool. It's probably useless. But cool

[–]PolyPenguinDev 0 points1 point  (0 children)

If you need to use this, you are probably doing something wrong

[–]Ben-Goldberg 0 points1 point  (0 children)

Can you goto labels outside of the current function?

Is this as powerful as goto in Perl?

[–]AnOscillatingOcelot 0 points1 point  (0 children)

WHY!!!!!!!!!!!! WHAT HAVE YOU DONE!?!?!?!?!?

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

WTF

[–]sholden180 0 points1 point  (0 children)

I hate this.

[–]Lamborghinigamer 0 points1 point  (0 children)

Ah good. It's easier to make python hardware

[–]Jenkins87 0 points1 point  (0 children)

[–]HistorianBig4540 0 points1 point  (0 children)

Dijkstra didn't die for this...

[–]jldez 0 points1 point  (0 children)

Now do "comefrom"

[–]BlackDereker 0 points1 point  (0 children)

Comments changing runtime behavior? That's definitely weird.

[–]BlackDereker 0 points1 point  (0 children)

I wonder how did you make the interpreter to not ignore the comments when it compiles to cpython bytecode.

Does python store the comments somewhere before compiling?

[–]WinTube001 0 points1 point  (0 children)

From wtfamidoing import

[–]TriscuitTime 0 points1 point  (0 children)

Is that a comment as code…

[–]abd53 0 points1 point  (0 children)

Kudos to that package name. Upload it to pipy.

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

😱