Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

3

In C++, constructors are special operators. There is special syntax for calling a base class constructor: class A { ... }; class B: public A { public: B() : A() { ... } // ^^^^^ }; If the base constructor is not called explicitly, the default constructor for the base class will be called automatically. This is important for C++'s memory model and ...


0

UML is the Unified Modeling Language it supports a range of paradigms for programming not just OO with its Class diagrams. Use whichever diagrams add value to your documentation or when discussing the implementation at a whiteboard or in review. Structural diagrams Class diagram - You can treat each module as a class for diagramming purposes. Package ...


0

So you want to describe the functional implementation of the application with a diagram You can use a sequence diagram to depict the functional flow among your modules. This is a bit more at a component level. If you are talking about specific logic and a bit more detail go for a State diagram Cheers..


1

Jay's answer is correct that you can do this thing. The normal way to describe this is that you'll be developing the python algorithm (function) into a "service" (standalone application) that your PHP app will "consume" (make calls to). This is a fine idea if the algorithm is complex enough that you want to think of it as its own program; sequestering your ...


8

The programming paradigm that organizes the software into functions is called procedural programming. For example, C is a procedural programming language. Most dynamic languages like JS or Python can be used in a procedural style. While you are also organizing your code into separate files, there is no commonly used name that describes this. For example, ...


-2

Make the parameter strongly typed, and make the type responsible for performing the conversions. An example of this pattern is the C# TimeSpan class. Instances can be obtained from various static methods with self-documenting names like FromMinutes. And through properties like TotalMinutes, the value of an instance can be expressed in various units. ...


2

Well, you wrote to take care of converting arguments to public methods to some unit system internal to the package so that private (or hidden, since we're talking about Python) methods don't have to "think" about units. so for yourself, you already see the major drawback of the "arbitrary unit" approach: it is way less tedious any less error prone to ...


0

Take a look at Crafting Interpreters. The later part about a Byte-Code interpreter is still being written but the basics of how languages are composed, and how to write a parser and interpreter are complete - and easy to understand.


1

I really like the answer about structured versus not, so I'm just providing a concrete example below. SimpleNamespace will accept keys that begin with _. If you're looking for a quick and easy way to turn, say, JSON you don't control into objects with field names, this is very handy: d = {"_id": 2342122, "text": "hi there!"} # Elasticsearch gives this id! ...


0

(Important Preliminary Consideration) Before attempting to answer the questions you asked, I would highly encourage you to consider renting a high-memory machine for the ML modeling tasks if you're already in the cloud and talking about batch jobs. A 500GB RAM box can be had for $5/hr these days, and it'll be worth every penny (if you have little enough data ...


0

Related code should be vertically close. You have the situation where, depending on how you look at it, different classes are related in different ways. I think the driving force here is the model and so I would put views related to a specific model in their own files views/foo.py views/bar.py.


2

The support for random.sample(a.keys(), 1)[0] is an implementation accident and can break down in future Python3 versions. There is good reason to recommend that neither choice() nor sample() supports a dictionary or a 'dict_keys' object as an argument. As Tim Peters say: The dict type doesn't support efficient random choice (neither do sets, by the way), ...


3

Q: For the functionalities that are similar for the mobile and web admin, how can avoid duplicating the code? Essentially, encapsulating the domain and the business logic in their own components and modules so the web layer acts as a driver or facade. This is what web interfaces are meant to be, an extension which allows our business expand up to the WWW. ...


0

For the first answer, i'd suggest creating a "service layer" that can be called by both RESTful API methods and controllers methods for the web admin, if your plan was serve web pages directly by the server. However it's a better practice to separate back-end and front-end. In this case, the back-end will have only to expose RESTful API that will be called ...


0

In Django, ForeignKey fields are not optional by default, so unless UserProfile is a field that should ultimately only sometimes exist on the User, it's best to create and assign it immediately, before you save the newly created User. You shouldn't make UserProfile an optional ForeignKey unless it may never get created and remain unset indefinitely. Having ...


0

This is about ownership and the responsibility to close the file. You can pass on a stream or file handle or whatever thingy that should be closed/disposed at some point to another method, as long as you make sure it is clear who owns it and certain it will be closed by the owner when you are done. This typically involves a try-finally construct or the ...


0

It's completely fine to have one TwitterClient per user. It seems like the program memory would dramatically increase if every user initiated the instantiation of a program object? Why, what instance data does the client object actually have? I believe it would only have the user's authentication data; the rest of it is just methods. If for whatever ...


2

If you want to execute user-input without giving the user the chance to mess with the computer, there are only a few options Allow the user to enter python code and pass that through to a sandboxed eval Design your own mini-language (DSL; Domain Specific Language) and create a parser and interpreter for it. Search the internet for an existing DSL that ...


2

If you really want to parse the user's input, you could have a look at the Lark library. It has an intuitive syntax for defining EBNF grammar with callback functions. The documentation is pretty good and one of the tutorial example is basically what you want. On the other hand, if you do trust your user so much, why not just use the path to a python script ...


1

On the surface, it looks like your trade-off is between performance and complexity. Performance As you point out, there's added performance costs to executing a subprocess. Complexity For the 3rd-party library to use a socket it must (obviously) be running. So your application will have to take on the added complexity of making sure that 3rd-party tool is ...


1

It depends. Using a subprocess is probably simpler/easier to implement, but like you've said, will probably perform more poorly than reusing a single process for multiple requests (there may also be overhead of initialization of some sort in the subprocess). The question is does that matter for your use case? If you're doing 1 request/second, the extra ...


Top 50 recent answers are included