Hot answers tagged

19 votes
Accepted

Exporting routes in node.js Express 4

You don't have to inject express into each modules. requiring express in each file will return the same instance. http://nodejs.org/docs/latest/api/modules.html#modules_caching Also, ask yourself ...
user avatar
19 votes
Accepted

Python exception handler to recommend package

An ImportError instance doesn't have a replace method. You can use e.name instead of messy ...
user avatar
  • 107k
16 votes
Accepted

List all classes in a package directory

Since the classes are all subclasses of _MyBase, they can be accessed via _MyBase.__subclasses__() after they have been imported:...
user avatar
  • 10.3k
12 votes
Accepted

Using async / await with dynamic import() for ES6 modules

Approach 2 does not work because accoring to MDN: import '/modules/my-module.js'; Is how you import a module for Import a ...
user avatar
  • 568
11 votes

Python exception handler to recommend package

First of all, this code doesn't work. e is an ImportError instance, not a string, and so it doesn't have a ...
user avatar
  • 256
7 votes

MongoDB Perl Wrapper

I'm the lead engineer for the MongoDB Perl driver with a couple of thoughts for you: you're using 'authenticate', which is for a very old version of the driver which is not recommended for use. In ...
user avatar
  • 171
6 votes
Accepted

Loading and Using Lua Scripts

I am not even remotely familiar with lua or how it works with Objective-C, so I can't really comment on any of these aspects of your code. What I can do of course, is comment on the Objective-C bits, ...
user avatar
  • 25.2k
6 votes
Accepted

Bitex - Cryptocurrency Exchange API Framework for Python

There's a lot of code here, so I'm just going to review bitex.utils. You'll see that there's plenty here for one review. Maybe some of the other reviewers here at ...
user avatar
  • 49.2k
5 votes
Accepted

Slider module and extending it further

document.querySelector While it is a great function to use, you are using in the wrong situations. For every time you use it, you are getting an array of elements ...
user avatar
  • 13.2k
5 votes
Accepted

Physics particle collisions

A couple of simple things I notice right off the bat. If you have a method which only calls another method, why bother having the first method at all? I'm personally against these one-line wrapper ...
user avatar
  • 4,869
5 votes
Accepted

Module to validate and sum a string containing no negative numbers

module.exports is just an object. Set properties on it that you want to expose. exports.add = add This is also equivalent in ...
user avatar
  • 545
5 votes
Accepted

Python Export Decorator

Personally, I'd prefer to use @export() or @export(globals()), rather than manually perform the ...
user avatar
  • 41.7k
5 votes

Modular square checker in ANSI-C

Missing Error Checks Always check user input, you are doing this correctly in the function scanMatrix() but you missed the check on ...
user avatar
  • 18.9k
4 votes

List all classes in a package directory

Using exec() is generally regarded as bad practice (https://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoided). Since you are trying to import ...
user avatar
4 votes

Combat simulator - single page JavaScript with requirejs from a Java Applet

I'm an experienced Java programmer who, upon realizing Java applets don't run in browsers anymore (I know I'm late to that party!), decided to bite the bullet and move to JavaScript. Yay! Welcome to ...
user avatar
  • 24.8k
4 votes
Accepted

Perl recursive copy and move functions

You've got a security vulnerability here just waiting to be exploited based on the fact you use the same interface for "The human" and "The Filesystem". All you need is for somebody to create a file ...
user avatar
4 votes

Cursor module for a text-editor

The names 'txtX' and 'txtY' don't say anything about the domain as 'line', or 'length' do. Someone would need to see how are you using that variable to figure out what it is. If you want to make the ...
user avatar
4 votes

Simple Java program - Coding bat sumNumbers

There are a couple things you can do here to make things simpler. The first is to make your inner loop a while loop instead of a for loop. With this idea, you can build up each number char by char, ...
user avatar
  • 3,512
4 votes
Accepted

Simple Java program - Coding bat sumNumbers

I want to know if the way I format my for loops and if else statements is good style. On the whole, yeah, looks good. I recommend you use braces for one-liner blocks as well. In this instance, I'm ...
user avatar
  • 2,730
4 votes

Raku / Perl6: A module to enable escape codes in the win32 console, naming suggestions

Since no one else has replied, here's somewhat of a "rubber duck code review" given that I don't know much about Windows, vt, and NativeCall. Plus I've got a suggestion about the API and module name. ...
user avatar
  • 381
4 votes

Linear Regression Class in Python

Toward optimized functionality and design since all crucial attributes x, y, x_mean, ...
user avatar
4 votes
Accepted

Modular Design Patterns in C

Don't hide pointers Don't hide pointers in a typedef: typedef struct moduleIF_CTX *moduleIF_CTX_t; This makes it really hard to spot when things are passed by ...
user avatar
  • 34.7k
3 votes

Somewhat less semi-primitive IRC bot - follow-up

Variables class Usually boolean flags does not help readability and, in this case, a boolean flag to perform an active action in object constructor (which should, in theory, just...construct the ...
user avatar
3 votes

Separate Ajax code in separate modules

For OOJS, I would personally recommend Angular.js. For the above code, here's you can impelment OOJS: ...
user avatar
  • 241
3 votes
Accepted

Listing an optional Python dependency in setup.py

A few small comments: The error message looks wrong to me. This is what the logic looks like to me: ...
user avatar
  • 8,475
3 votes

Binary index tree optimization

Binary Indexed Tree is a suitable data structure for this question. However, you have to be careful of how you want to use it. For me, I would use it for storing values of "Functions". Based on the ...
user avatar
3 votes

Custom module of common functions

What you're looking for in your cache decorator is functools.wraps. Otherwise, very handy!
user avatar
3 votes

Physics particle collisions

I also hate large files. My rule of thumb is a maximum of 300 lines per class. You mentioned that you wanted to put methods in helper classes. Also you said you were not sure about refactoring ...
user avatar
  • 5,340
3 votes

Project Euler module

Use .format Using % is considered old style, so: ...
user avatar
  • 27.3k
3 votes

Merging with different modules

This is nowhere near the full answer, but I just want to touch on the initialize method of Merge real quick since it was the first thing to jump out to me. ...
user avatar
  • 170

Only top scored, non community-wiki answers of a minimum length are eligible