Re: Same import lines again and again

2019-08-25 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Same import lines again and again

@10, I know what your demonstrating. I know that too. I've always done it though not just for readability and clarity but for understanding too. If I see you write an include file and use a function that you didn't #include the file for (but the #include was hidden/indirect) I immediately would classify that as either UB or some kind of coding mistake, and it would be quite confusing, even if its not UB or a coding mistake. (As a side note, Rust prohibits this kind of behavior. You cannot have "hidden use" declarations. You are required to "use" everything that you will use in your code or the compiler will wine about it, which is a good thing IMO and something that C/C++ compilers need to adopt.)

URL: https://forum.audiogames.net/post/457677/#p457677




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Same import lines again and again

2019-08-25 Thread AudioGames . net Forum — Developers room : Rastislav Kiss via Audiogames-reflector


  


Re: Same import lines again and again

@9: that's true, however I was talking about hidden includes, not including one header more times.if you write:#include You get not just objects like cin, cout, but also string which comes from the string header included by the iostream header.So after including iostream, you can go and use std::string in the file where you included it.However because just from #include  it isn't obvious that string will get included as well, it's considered to be good practice for readability to include it explicitly like:#include 
#include Despite it isn't needed for compiler as it will know already from iostream what string is.Of course it could look overdramatising showing where string comes from, but in a more abstract environment it can help much demonstrating, where have class dependencies appeared from.I had quite funny times studying Ruby. Although I was rather looking for peculiarities than doing a senseful learning, with Ruby's principle of connecting various methods directly to datatypes such as int from external sources, importance of tracking and writing imports gets a fully new dimension.I just couldn't believe how universal an int in Ruby is. Best regardsRastislav

URL: https://forum.audiogames.net/post/457670/#p457670




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Same import lines again and again

2019-08-25 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Same import lines again and again

I always import/#include/use/whatever everything each file will need in a project even if its not necessary. It has no overhead and there are no consequences of doing it, and evry programming language I know has built-in optimizations to get rid of duplicated code in the generated code. C++ has #pragma once and #ifdef/#endif, for example. So I can #include  as many times as I like and it will only be included once in my whole program.

URL: https://forum.audiogames.net/post/457591/#p457591




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Same import lines again and again

2019-08-25 Thread AudioGames . net Forum — Developers room : Rastislav Kiss via Audiogames-reflector


  


Re: Same import lines again and again

Hi there,just for case someone was as dump as me, when i was starting with Python, I want to add here, that a Python file is expected to hold a module.That was something I didn't get from first and though, that it is a file per class model, like in C# or other similar languages - C/C++, BGT, etc.Thus I made a .py file for every class and then faced exactly this problem, the amount of imports has grown insanely and I even wasn't able to get what exactly it does when I import a .py file.Well, now i know, that every Python file is a whole module, or a namespace in C terminology and is expected to work in such way.Thus it is not space wasting to write imports to modules, as they quite well describe, what the module relies upon and help in figuring out where classes and functions used in the module comes from.That's the reason why I wouldn't personally keep imports to another module, although it is technically possible.Like in C++, the iostream header includes string header in it, what means, if you include iostream, you can use string as well without including it explicitly from the code. However for a reader, it isn't obvious that the string include is hidden behind iostream include, so despite it would work, including both is recommended to keep the code readable as much as possible.That are however just recommendations. Go with the option which makes most sense to you, so you will understand it even after a long pause from the project.Best regardsRastislav

URL: https://forum.audiogames.net/post/457567/#p457567




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Same import lines again and again

2019-08-25 Thread AudioGames . net Forum — Developers room : Ilya via Audiogames-reflector


  


Re: Same import lines again and again

what i do is make a file which is purely for importing stuff, i would do something like the folowing.def importer():    import sys    import time    import requests    import random    import pygame    import pyglet    import osimporter()then in each new file i would import my importer file

URL: https://forum.audiogames.net/post/457558/#p457558




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Same import lines again and again

2019-08-24 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: Same import lines again and again

Well, individual files have to import to their local names spaces, but there are a few ways to edge around that. What you can do in create a dependances script and then import that. So for example lets say you have two scripts, script1 and script2, both have to import a bunch of things. Rather than importing everything to each script, you just import the dependances file, like so:#dependances.py
import numpy
import os
import sys#script1
import dependances#script2
import dependancesThis way, your only ever importing a single file.

URL: https://forum.audiogames.net/post/457534/#p457534




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Same import lines again and again

2019-08-24 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Same import lines again and again

That is an early python version thing.  At one point, you just had to have a class inherit from something else, and the object class is as basic as you can get.  Newer versions of the language allowed for an automatic inheritance from the object class, hence your statement working.

URL: https://forum.audiogames.net/post/457530/#p457530




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Same import lines again and again

2019-08-24 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Same import lines again and again

Right, but you will have to re-import the module again if you want to use it in another file, correct? I am asking if there is a permanent way to stick a module in all of the name space without retyping the import statement for every file you need it in.

URL: https://forum.audiogames.net/post/457525/#p457525




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Same import lines again and again

2019-08-24 Thread AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector


  


Re: Same import lines again and again

I also have a question: why do so me people create there classes like this:class app(object):and not just class app():what is the difference between the class app(object):  and class app():?sorry for asking, and i was also wondering how do i get the full function of a module by only importing it once in a file across multiple files.

URL: https://forum.audiogames.net/post/457528/#p457528




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Same import lines again and again

2019-08-24 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Same import lines again and again

Right, but you will have to re-import the module again if you want to use it in another file, correct?

URL: https://forum.audiogames.net/post/457525/#p457525




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Same import lines again and again

2019-08-24 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: Same import lines again and again

Imports are generally done at the beginning of a script, are global, and don't need to be repeated. Once a module is imported it essentially increases the library of functions and classes you can create, and you can access it anywhere within your program, which makes re-importing it purely redundant. For example:import os

#standalone
print(os.path)

#in a function
def path():
print(os.path)

path()

#in a class
class example(object):
 def __init__(self):
 print(os.path)

a = example()In every instance, whether its on its own, in a function, or in a class, I can use the OS module anywhere I choose without having to import it ever again beyond at the beginning of the script. In the case of the classes, you could re-initialize the classes by going "a = example()" to create an entirely new instance of that class every time, again no imports necessary.

URL: https://forum.audiogames.net/post/457517/#p457517




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector