10
votes
Accepted
Skipping over failed imports until they are needed (if ever)
There is one issue with your approach which is, in the case of multiple import failure, only the last one can be properly reported:
...
8
votes
Accepted
Dynamically loading CSS files based on URL or URI in PHP
Most of questions you are asking are not fit for this site and your code does not work as intended but this is an interesting case to review
The grave mistake
Adding anything to your code just in case ...
7
votes
Skipping over failed imports until they are needed (if ever)
That's an odd use of the word "default", which, etymologically speaking, means to remove failure, and generally refers to a fallback setting that "just works". I suggest calling it ...
7
votes
Skipping over failed imports until they are needed (if ever)
This answer builds upon the solution presented by Mathias Ettinger
If you want to get rid of the try: ... except: ... boilerplate you could implement some kind of ...
6
votes
Skipping over failed imports until they are needed (if ever)
Whenever you find yourself trying to replace a standard language feature, the first thing you should think is,
There's probably something I'm missing. What's the standard approach to this kind of ...
5
votes
Dynamically loading CSS files based on URL or URI in PHP
Your current battery of if conditions needs a re-think. $_SERVER['PHP_SELF'] -- as long as it has a non-falsey value will evauate to ...
5
votes
Accepted
Accessing multiple dynamic libraries with the same extern C methods
The code looks correct. It looks like a weird mix of C and C++ though.
Assumptions
There was a statement that they share the same base class, but I am not sure what it means if they all use C style ...
4
votes
Script to load other .js scripts
few suggestions...
I would lose the jQuery part and stick to vanilla js for several reasons
jQuery's getScript doesn't add a script to the page like your vanilla ...
4
votes
Code to fill PE import address table
; // https://artfulcode.wordpress.com/
; // https://github.com/cmovz/
; // License: use it as you wish, just keep this notice. No liability taken.
The comments ...
4
votes
Making a graph of the import structure of a program
If a Python module contains no imports, then the code in the post fails with an error like this:
...
4
votes
3
votes
Accepted
Efficient, typesafe runtime selection between "compiler-checked" sets of static config constant
Using class inheritance
You can use class inheritance, the constants do inherit. I don't think the boilerplate is that much compared to the constexpr variable approach with designated initializer. It ...
3
votes
Importing modules for private use in Python
NO
This is not pythonic... and this is ugly... aaah, I can't get that code out of my head...
There is this thing called __all__
1. How does it work
Make a list, put ...
3
votes
C++ DLL Injector
Compilation flags
Please specify for which sets of compilation flags this code is expected to work (it will break if compiled with UNICODE defined, as described ...
3
votes
Accepted
Recursive autoloader to find PHP files
There are several ways to improve the code.
Let's start with the constructor.
You should not make any assumptions about the place of a file in the current file system, because that makes later ...
3
votes
Accepted
Auto loading code
In order of most to least relevant.
1) There are lots of frameworks for PHP websites / apps and you should consider using one. People have written lots of code that you can take advantage of and won'...
3
votes
Dynamic module import in Python with exception handling
I mean I'm not a fan of it since it's basically just a list of
statements to execute, but then again, the solution via globals and
...
3
votes
Simple import system for a large shell program
I don't have enough reputation to comment, but I am rather intrigued by your script, because I also enjoy writing large programs in the shell, and recently have been trying write modular shell scripts....
3
votes
List all classes in a package directory
The limitations of using the __subclasses()__ approach are:
You need to load the classes (i.e. have them imported), otherwise it will not work.
If you have ...
3
votes
Import "izip" for different versions of Python
This is roughly twice as fast as using a try/except:
import itertools
zip = getattr(itertools, 'izip', zip)
3
votes
Load modules conditionally Python
Sanitising your inputs with argparse
As has already been mentioned in comments and @eikonomega’s answer, running arbitrary code from the user is generally dangerous. Using ...
3
votes
Accepted
PHP autoloader that uses array of file paths
Efficiency, Efficiency, Efficiency!
I don't know how big your applications are, but I wouldn't want to recursively scan all the files in my applications, every time a PHP script wants to execute. Want ...
3
votes
Script that uses an uploaded excel file to import data to the database
Some quick comments:
The function checkURL is called in a loop, but inside that function you close the Curl connection every time. Instead you could speed up ...
3
votes
Accepted
Python preprocessor for pipes
Unused
import sys as _INTERNAL_SYS is unused. You can delete this.
slots
Two of your classes define __slots__, where as three ...
2
votes
Accepted
Dynamic loading of Javascript dependency graph
Your code is already good, but there are just a few things to note:
You are not in control which order the browser will complete the loading of the scripts you have added to the DOM, that might be ...
2
votes
Dynamic loading of Javascript dependency graph
I have JavaScript module for loading dynamically script files by dependency graph:
But... why? There are libraries out there that already do this. Take for instance, RequireJS. Most libraries out ...
2
votes
Dynamically loading CSS files based on URL or URI in PHP
I wonder if you are asking the right question. I can't help but wonder where this code block could possibly run in order to make sense.
I will have to assume a lot, so here we go:
Why don't you ...
2
votes
PHP Autoloader - For classes, traits and interfaces
First, I disagree with the comment of xReprisal about static. A Static method is a useful tool and spoiling it is a waste. However, you are also using a static field and it is not recommended (...
2
votes
PHP Autoloader - For classes, traits and interfaces
First of all you should use static methods and properties only
when there is good reason to do so. Generally you should default to non-static.
$path property can ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
dynamic-loading × 70python × 20
php × 12
c++ × 9
javascript × 8
java × 7
python-3.x × 7
file-system × 7
beginner × 5
library × 5
c × 4
error-handling × 4
object-oriented × 3
vba × 3
windows × 3
modules × 3
performance × 2
jquery × 2
c++11 × 2
design-patterns × 2
parsing × 2
excel × 2
css × 2
comparative-review × 2
security × 2