Tag Info

Hot answers tagged

8

Why cant be a global Standard to do all Simple and Common things? We tried that. The concept was called UNCOL, and the idea was that it would be ported to every architecture in the world, everyone would use it for everything. As you can tell, things didn't work out that way. Why not? Because programming is a complex activity, and there is no single ...


7

As far as I know, you cannot execute a Python program (compiled to bytecode) on every machine, such as on windows, or on linux without modification. You are incorrect. The python bytecode is cross platform. See Is python bytecode version-dependent? Is it platform-dependent? on Stack Overflow. However, it is not compatible across versions. Python 2.6 ...


7

I generally avoid having the class know how to serialize itself, for a couple of reasons. First, if you want to (de)serialize to/from a different format, you now need to pollute the model with that extra logic. If the model is accessed via an interface, then you also pollute the contract. public class Image { public void toJPG(String filePath) { ... } ...


6

Let's immediately get the Turing-completeness disclaimer out of the way and say any language can probably approximate any runtime feature of any other language. Good? Good. The main difference between the Node.js approach and a Python threaded-server (or a typical Java HTTP server implementation) is that Node.js is single threaded while the latter two are ...


6

Go's primary design goal is to be simple to learn and simple to use even for sub-mediocre programmers, so if you want to write idiomatic Go the anti-pattern you should avoid the most is the "Clever Code" anti-pattern. As for a good reason to not allow nested functions even though you allow anonymous functions - one of the differences between Python and Go ...


4

What matters about programming languages are the semantics, not the syntax. However, syntax is a vehicle for semantics. It is easy to show that two languages can have incompatible semantics (e.g. unrestricted pointers vs. memory safety, or differences in type systems). Let's focus on the syntax and semantics of variable declarations. When we declare a ...


3

It seems that with this type of architecture developers no longer have to maintain large codebases, and the applications themselves are mostly thin wrappers around databases. You've fallen into the NoSQL mindset. "Hey, why should we learn this complex thing called SQL that the old-timers use? Why don't we just use a giant key/value store for ...


3

Can I develop in an 'interactive mode' the same way in C# - that is, load in some sample data, write methods interactively to ensure they're working right, then push methods up to classes as they're completed? Not the same way. There isn't really such interactive tools for C# since the problems you're usually solving are large enough to make that ...


3

In general, in Python I favor using functions over subclassing internal classes. In the end, if you write your String -> dict method, you end up working with a dict, pure as the driven snow. Just put your functions in a sensible module and import them only where needed; this will also encourage you not to import the functions everywhere, which will help ...


3

There are several tradeoffs you've made that are not immediately obvious. By running your own builds, you're responsible for keeping track of upstream updates, particularly with regard to security. You're also suspectible to changes in your environment that would've been handled in distribution packages, but you again have to monitor and re-integrate such ...


2

This is the job of the package manager. In the case of Python: pip. If you package the library you are building and specify its dependencies, your users (grandpa), will simply need to run: $ pip install --upgrade <name-of-package> to get the latest version you've released and all of its dependencies. If you don't want to publish your code online, ...


2

What you are looking for is called a REPL, a quick search for "C++ REPL" gets you to Cling, but I have not used it. I'm not sure what is the real benefit from using a REPL over to use a debugger with an interface that you are comfortable with. Static typing should help you get the code right before ever running it, also IDE's suggestions become much better ...


2

It's true that the bytecode is not suitable as a distribution format, but that doesn't mean it's useless. Aside from improving startup time on a given machine, after the first run, interpreting bytecode is also far simpler than interpreting an AST or, god forbid, interpreting line-by-line. Bytecode is a more low-level, more regular, more compact (both ...


2

The OOP way is to combine together polymorphism and recursion. A binary tree is defined as either empty or a set of value, left and right where both left and right are binary trees. To represent it properly left and right must be binary tree themselves, even if they are empty. To represent that in object oriented way, we'll have a tree base class and node ...


2

A common way is, to define one global logger at the beginning of the module with: import logging logger = logging.getLogger(__name__) so it's easier to assign different log-levels to different modules. If you don't have a distinguishing logger name, you can directly use the log-functions of logging; instead of logDebug simply write logging.debug.


2

Yes it is, because there is no state being mutated. The line branch_counts = [count_leaves(b) for b in tree] can be interpreted as a simple binding (like a let statement in Haskell or Lisp), as there are no further reassignments or mutations. Additionally, you could reformat it like this to make it clearer: def count_leaves(tree): return 1 if ...


2

I would suggest implementing command line parameters and command line help using argparse. The different functions could then be selected by command line options. If others without python installed need to use your program, then I would package it as an executable using pyinstaller. Pyinstaller can be used to build 3 possilbe executables: onefile, onedir ...


2

Have the 8 function calls wrapped in if __name__ == '__main__': Then you can call the script by running python NAME_OF_YOUR_SCRIPT.py If you need to pass any variables in when running it, use the argparse module


2

You are confused between generators and iterators. They are not the same concept at all. Iterators are great and ubiquitous in Python. You should use them a lot. Both my_func_gen and my_func_list use them. Generators are a lazy way to build iterables. They are useful when the fully realized list would not fit in memory, or when the cost to calculate each ...


1

Arguably the reverse is true; microservices are attractive because of limitations of the languages currently used. This is why you see two distinct camps in microservices: small ones written in dynamic languages that lack a built-in usable concept of a documented and statically checked interface. So they build one themselves out of HTTP and tests. Much ...


1

asyncio is a set of libraries. The PEP and implementation define event loop abstractions, protocols for tasks to interact with the event loop, and various I/O classes and concurrency primitives that can be used in asynchronous code. The way to write these tasks is/was to write a generator and the way to wait on the completion of another task is/was to yield ...


1

I can understand the fact that Java needs both a compiler and an interpreter. It doesn't. There's nothing in the Java Language Specification that says that Java needs to have a compiler. There's also nothing in the Java Language Specification that says that Java needs to have an interpreter. Whether to use an interpreter, a compiler, or a combination ...


1

The kind of iterative development you're speaking of is typically done via Unit Tests in C#. Add a Unit Test project to your solution. Add aUnit Test class to the test project. Define the public API you want to create. Write a test to exercise one of the class's members. Run the tests. It should fail. Implement the functionality. Run the tests. If ...


1

This: app.route('/', method='GET')(home) ... Is the same as this: func = app.route('/', method='GET') func(home) In other words, app.route(...) returns a function, which is then called.


1

You probably want to use something like the visitor pattern, or the strategy pattern. something like (assuming a few refactors): services = [a,b,c] # add more as needed accum_strat = lambda l,s: s.Find_Service(l).GetVal() accum_list = [[] for x in range(len(services))] for l in locations: for srv, lst in zip(services, accum_list): ...


1

Serialization is a two part problem: Knowledge about how to instantiate a class aka structure. Knowledge about how to persist/transfer the information that is needed to instantiate a class aka mechanics. As far as possible, structure should be kept separate from the mechanics. This increases the modularity of your system. If you bury the information on ...


1

Generally speaking, you should not be modifying the source code files of third party code unless they're the type of changes for which it would make sense to contribute them back upstream (e.g. bug fixes). Obviously, there are exceptional situations where you may wish to go ahead and modify those files anyway, but you usually want to avoid forking the ...


1

You could create @property decorated functions. In the setter one, you make sure you have something that calls all the pre-defined callback for said property. This is a visitor pattern really. So, in untested and incomplete code, something akin to this: @ook.setter def ook(self, value): self._whatever = ook for func in self._ook_callbacks: ...



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