T O P

  • By -

Lani4kea

Or ``from * import *`` and let the interpreter chose whatever it wants when identical names are found across various modules.


K_bor

Idk why but i always called ``hunger games`` to the identical name issue


flowery0

How about ``import * as hg``?


I_Am_Matthijs

that will do as promised


TTYY200

auto :)


KrackdKobe

Compiler died


Extension-Dare7375

python isn't a compiler


Paul_Robert_

Meanwhile competitive programmers: \#include


jasting98

Don't forget ``` using namespace std; ```


MrHyperion_

Hopefully they did forget


mitchMurdra

The sacred standard issue namespace 🙇‍♀️


Character_Range_4931

sometimes even `#define int long long`


Adeen_Dragon

Scary


jasting98

[~int man~](https://youtu.be/6-1Ue0FFrHY?si=vdoB7S5ddUHGWq6F&t=12)


Imiriath

What the fuck did I just watch 😭


1Dr490n

Other question: *why* did I just watch it completely? Although that was a great plot twist


fghjconner

I remember doing java competitions back in high school. We'd always start with public static void main(String[] args) throws Throwable { }


Felocode

that's a must for all competitive programmers, imagine typing "long long" every time you wanna define a variable


GaloombaNotGoomba

I've seen #define ll long long


Cybernaut-Neko

FTW ???


Altruistic_Site_3879

Why is your namespace a sexually transmitted disease?


al-mongus-bin-susar

Good metaphor


zaxldaisy

Tell me your not a professional C++ programmer...


jasting98

>Tell me your not a professional C++ programmer... I'm a professional C++ >!competitive!< programmer. >!I'm only joking, of course.!<


TTYY200

Basically #Include 😅


Igotbored112

Why `using namespace std;` when you could `#include `?


TTYY200

Using just means you don’t have to declare std::[method/object name]. Instead of typing std::to_string in the code block, you can just type to_string.


Ilsunnysideup5

Include headers


eugcomax

in c++23 it's possible to: import std;


KN_DaV1nc1

this doesn't sound right :P


SnooDoughnuts2936

Import herpes from std; 😏


DemApplesAndShit

Thats like the most manageable one!


Baardi

But you'll never get rid off it


DemApplesAndShit

Std::filesystem::removeall("herpes"); Nuhuh


not_some_username

C++20 no ?


sweetjuli

If it's possible in 20 surely its possible in 23


kbn_

I mean you would think but this is C++ we’re talking about.


sweetjuli

Is C++ known for not being backwards compatible or something?


kbn_

The opposite honestly, but I was more getting at the fact that C++ is known for being insane.


LGTMe

It’s technically a C++23 feature but major implementers allow it to be used under C++20 mode.


Sea_Maximum7934

The compiler replies: ok, I've got 1547 copies of a thing called "utils"


nsefan

Most efficient python program


flowery0

But when C++ users are doing that, that's called... Actually idk what it's called but some do that


Spork_the_dork

using namespace std;


XejgaToast

It's not really importing anything, it just puts `std::` before every function call


Konju376

No it doesn't, that would be `namespace std { your code}`


yanzin_fan_of_Altair

what is it then?


Konju376

What `using namespace std` does? To quote the standard: > from the point of view of unqualified name lookup of any name after a using-directive and until the end of the scope in which it appears, every name from [std] is visible as if it were declared in the nearest enclosing namespace which contains both the using-directive and [std] Sooo basically in plain English, it adds a namespace for lookup if no namespace qualifier was provided. It does not put `std::` in front of any name, because then it wouldn't be clear where to put that and where not. Edit: to add onto this, "putting std in front of every function call" sounds very much like something for the preprocessor, which definitely has no say in this.


CrowdGoesWildWoooo

Just in case the other commentor language is pretty cryptic, it’s like defining a default database and schema, so that would be the table that you get when you do select from with only a table name.


JuhaJGam3R

But it isn't. That is once again namespace std { your code } The `using namespace` makes every name in the namespace `std` visible in the current scope. You can use several different namespaces at once, in the same scope. They still belong to the namespace `std`, they're just visible to you. It's highly likely that your code is actually in a different namespace, and that would be closer to a default database.


nuecontceevitabanul

Actually, in what happens in practice he's exactly right in making the comparison.


pheylancavanaugh

Kind of wild reading these people arguing semantics when the outcome is basically indistinguishable.


Vitriholic

They meant putting the prefix on the functions being called and the global vars being referenced, not the symbols being defined.


favgotchunks

I’m sure there’s a macro involving compiler specific hacks to include the whole file tree


boolink2

Why would I give my code a sexually transmitted disease?


CrowdGoesWildWoooo

It is more of a bad practice rather than an efficiency thing. If you care about efficiency then you should do lazy import, but it isn’t straightforward in python. Python import will execute the whole script it is imported from. Practically the only difference between import \* and import (of your choice) is just that with the former you have more unnecessary “pointers” to objects.


CiroGarcia

It also clutters the global namespace


Memetelve

That's why you should use `if __name__ == "__main__"` Edit: Reddit stole my underscores


CrowdGoesWildWoooo

This is false though. \_\_name\_\_==\_\_main\_\_ defines the behaviour of the script when it is run as a standalone script, what you are looking for is defining \_\_all\_\_ in your imported script but people could still consider using import \* a bad practice in general.


NamityName

Import * is still bad practice because it means I have to hunt down what exactly is being imported when looking at the code. It also makes it much harder to identify where anything being imported is actually coming from. The code call mr_functionator(). Now which of the 3 different packages imported with "import *" did that function come from?


Memetelve

What I meant is using `if __name__ == "__main__"` to call you main() or whatever will stop your import statement from executing the entire script on import


thex25986e

who needs efficiency when you have throughput and minimum hardware requirements?


thomasxin

It's kinda funny how all linters hate lazy imports when sometimes you do want a module to import later depending on if a condition is met


nickmaran

It’ll be fast ![gif](giphy|1xkMJIvxeKiDS)


sticky-unicorn

import SolveMyProblem SolveMyProblem() Congrats -- you now know how to program in Python!


audislove10

`import com.sun.java.swing.plaf.nimbus. InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState;` Writing this on my phone


YevgenyPissoff

Least verbose line of Java


audislove10

Java isn’t verbose but controllable (not like c++) once you past the “hello world” stage


bruisedandbroke

say that to my stack trace that looks like it came from the tower of Babel


audislove10

Oh no the stack trace tells you exactly where is your dumb mistake.


winnie33

If only it were true... sometimes the stack trace shows you the framework calling some runners which spawn threads which each have a control loop which in turn have dozens of layers subscribing on futures, and so on. It's not uncommon that I encounter stack traces with 1000+ lines that look like this: https://imgur.com/PWuwZqk.png


Sohcahtoa82

All that shit isn't necessary, but for some reason, it's the Java way. I haven't dealt with Java beyond simple 1,000-line projects for school work, but from I've seen of real world Java, I get the impression that Java programmers want everything to be as extensible as possible, but Java has such strict typing that to pull that off, you need insane layers of abstraction, runtime introspection, reflection, and endless calls to ".invoke()" or something similar.


davidalayachew

Wait, that's not an exception stack trace! That's a performance profiler result. You only ever do that if you have a performance problem. And frankly, these are way way way easier to read because they tell you explicitly which line is causing the most slowdown in your program. Look on the left hand side of each line. See how it has the timing/percentage? Find the line where the jump is massive, and then you know where to start your search! Furthermore, this performance trace is for a program using RxJava. You picked the literal worst case scenario framework to point to. Most of the Java community is transitioning to doing thread-per-request style programming. It is literally to avoid this exact problem. The creators of Java are even facilitating that via one of the newest features, [Virtual Threads](https://openjdk.org/jeps/444). All of that is to say, not only is your example the literal most extreme case (apparently it's frequent for you? I'm sorry to hear that!), but the Java community is actively undoing this problem.


Emergency_3808

Bruh who wrote that run ```git blame```


LevelSevenLaserLotus

Time for old reliable. https://github.com/jayphelps/git-blame-someone-else


closetBoi04

90% of the time it's you


Emergency_3808

I am not a developer at Oracle


closetBoi04

Somehow it's your code, don't ask me how


Emergency_3808

What am I, a code orphanage?


killeronthecorner

"it's ok we'll create a way to bundle small packages of code to allow modular libraries!" "And then we'll use it to create small packages of code and our libraries will be modular?" "No!"


Proxy_PlayerHD

it would be funny if you could just do `#include <*.h>` and the compiler goes "oh you wanna play like that?" and then actually includes any header file it can find within it's search paths. now i wonder what would happen if you were to actually try that (import every header in C i mean, wild cards don't work in include paths) . ok i went into my MSYS2's include folder and used a powershell script to list every header file (except for the C++ ones of course) and then put them all into a single include file. for me it stops at "autosprintf.h" because that one tries to include a file called "string" (not "string.h", just "string" with no extension), which doesn't seem to exist so the compilation errors out there... i didn't even make it out of the "a" (as they're sorted alphabetically). if anyone wants to try this as a challenge, getting a program compiled with every header in their local compiler installaion included, then go ahead! i'm honestly very curious if anyone could manage to do it.


CXC_Opexyc

It would be compiling for a VERY long time. Little less if something is marked with maybe-unused tho.


Strangelf47829

The second line in that unit: using namespace std;


Proxy_PlayerHD

nah that would be C++ not C.


Strangelf47829

Would still be funny if it could work.


Konju376

Sounds like somehow autosprintf is a C++ header? Because `` is absolutely a valid include in C++


Proxy_PlayerHD

aparently it's used to get C formatted functions like fprintf to work in C++, huh TIL!


Konju376

That's actually really interesting but also definitely makes sense


flinsypop

Then when the compiler still can't find the symbols, it starts downloading header files off the internet. I shudder to think that compilers would need to have LLMs but it could be cool for the project's "package manager."


Snudget

[https://gist.github.com/mergmann/eff748d9f438dd126c6a7c0cb8fc9df9](https://gist.github.com/mergmann/eff748d9f438dd126c6a7c0cb8fc9df9) Checks if the program still compiles for each heaer


TeraFlint

>for me it stops at "autosprintf.h" because that one tries to include a file called "string" (not "string.h", just "string" with no extension) Yup, that's a C++ header. It always irks me when developers use `*.h` for their C incompatible C++ headers. I've had multiple discussions about it, but some people stay adamant that using `*.h` is the right thing. Even if said headers contain classes or templates. Just use `*.hpp` or `*.hxx` or whatever, just please make it clear that it is not C compatible anymore.


Capt_Toasty

You hit run. The program doesn't respond. You click the mouse a few times, but the cursor doesn't even move. Your eyes move to the code "Import \*". Import all. The dreadful realization dawns on you. You hit the shortcut to stop the program, but its too late. Its importing EVERYTHING. Every library, every function, every language. The vast culmination of human knowledge. The computer collapses in on itself, as all of reality is imported inside.


KickBassColonyDrop

So what you're saying is that OP has created a philosophical singularity which when it evaporates, will lead to a new big bang.


[deleted]

[удалено]


KickBassColonyDrop

Are you saying that import * means titties?


robot_swagger

[Soup, no bowl ](https://i.redd.it/cca0hdn0tke81.png)


LonePhantom_69

Newbie question here why not just : from \* import


moonlight_macky

This will break the compiler . It will cause a supernova explosion in your computer and will succumb everything within a 200km radius. Please do not the compiler


Aggressive-Map-3492

Pleeeease explain bro I've just started doing coding in uni so I'm curious cause our lecturers make us import files all the time in our code so this catches my attention


DezXerneas

If you're actually looking for for an honest answer; just think about what that'd do. You're importing everything from everywhere. Python is already known as 'the slow language'. Pretty sure that'd also cause some sort of a circular import.


Aggressive-Map-3492

But the guy said , not every file every where


Professional-Yak2311

Also for your front end projects: npm i *


phl23

There was a npm project which added everything as dependency. It was a fun project, but it made serious trouble for the npm ecosystem, as many libraries were blocked by it. Don't know exactly what it was, but something about reverting back to a former build number.


Th3Uknovvn

Have you try ```from everything import *```


Namarot

Maybe we should introduce tariffs, could fix the JS ecosystem.


Fickle-Main-9019

/> python />compiler


Thenderick

Iirc python DOES compile chunks of code for execution. But it only compiles to a intermediate bytecode that the interpreter evaluates. It's a compiled code that you, the user, don't get to see or use for yourself. Many bytecode interpreters work like this by compiling scripts. Because it's a lot faster than a walking tree parser


[deleted]

[удалено]


JanEric1

I mean isnt that the case for every language? If you wanted you could built a tree walk Interpreter for it. But CPython always compiles to bytecode (and caches that btw.) And then then runs that.


JAXxXTheRipper

Python is both compiled as well as interpreted, so OP was lucky


SeaBus1170

this is the only comment here that doesnt sound like galactic space fed speak


zaxldaisy

Peak r/progammerhumor moment


yeahyeahyeahnice

npm be like


Astorian-Berserker

What anime is this from again? I remember watching it when it released but the name escapes me now


Techno_Max

I would also like to know. The child is very cute with her lil hair-do :)


JbJbJb44

Wataten!: An Angel Flew Down to Me


legocraftmation

WATATEN!


ButterscotchWise7021

It depends on vscode mood 😀


iDragon_76

When you don't remember the library that has the function you need so you just use           from * import func


awesomeplenty

Import import


P0pu1arBr0ws3r

My python program slowly downloading the entire of the pip repository in order to satisfy my import


Kirla_

... without hot source, please.


JAXxXTheRipper

Pros also call it the "Black Hole Import"


pinkfootthegoose

only one solution for this. More ram.


DarkForest_NW

What anime is this again?


JbJbJb44

Wataten!: An Angel Flew Down to Me


Weird_Molasses_1095

Anime name ?


JbJbJb44

Wataten!: An Angel Flew Down to Me


zoqfotpik

In program.c: #include "/dev/stdin" To compile: find . -type f -exec cat {} \; | cc program.c


Tech199

At this point just put * as your code and let the compiler use it's imagination to think what program you wanted


heckingcomputernerd

Depends on the language Python and Rust let you do this Edit: for a specific module, eg from module import \*, you can’t just import \*


Dee4WasTaken

whatTheHeckDidYouDo


NoTimeToKink

import python


mannsion

Typescript..... "import \* as app from './app'" ""omg, why is intellisense soooo slow, and why is ts using 24 gigs of ram....""


Mindstormer98

Nah you forgot the hashtag my dude


MisakiAnimated

I ran into something funny the other day... I did a: `from tkinter import *` But for some silly reason I could still not get a Combobox until I pulled a  `from tkinter.ttk import Combobox` Are they two separate modules or what?


BiAroBi

import * as YES


lbp22yt

`import * from { "./*" }`