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

Hot answers tagged

5

There's nothing wrong with it. You just lose Separation of Concerns, that's all. You can write single-page applications in precisely this way using Vue. Code folding in Visual Studio Code insures that the thing stays readable. But the practical limit of such pages is about 20,000 lines of code (including the HTML). That is a lot of code in a single file,...


4

There are many different types of machine learning. The one in your example is basically trying to draw straight lines between the a and b labelled points. The lines are equivalent to your word mapping and are saved in memory as part of the classifier after you have called the train function. To apply machine learning to your article tagging problem you ...


3

Merging all code into one file, and not utilizing functions (as your code example suggests) also removes the advantages you gain with abstractions. Even a function is an abstraction that when properly named encapsulates not only logic, but an idea that can be understood by a programmer by simply reading the name instead of spending the time to understand the ...


2

This sounds like a good approach to me. You ask about this: If I am using acknowledgement my understanding is that even if one of my consumers dies the queue and message will not be deleted. Both will persist and wait for the a new consumer indefinitely. Not in all cases. You can set a TTL both on the queue and on each message. If the consumer dies and ...


2

Looking at your code, if you have any requirement to have a unit test cover the processRequest method, without dependency injection it will be impossible for you to provide a mock object for MyObjectClass in your first example. If MyObjectClass interacts with anything (such as making an HTTP request, write / read from a file, save / read stuff to or from a ...


2

Duck Typing I'm not a PHP expert but in any programming language using attribute bags as objects, there always exist functions to ensure that a given attribute is defined, and how it is defined. Essentially all the basics you need to enforce Duck Typing. Spaghetti Checks This does leads to a distribution of such checks throughout the code base. Which is ...


2

If your program requires that every item has a name, then you should model the item as a class with a name property, instead of using an array. Then you can change the Register interface so that it is clear that it returns an Item (which has a name) and not just any random type. class Item { public $name; // other properties } class Register { ...


1

What you need is a separation between mechanism and policy. You should have model modules that interacts with your data storage and implements business rules. Then these are wrapped with as many modules that implements permissions checks as you needed. As you're using PHP, an additional risk exist that you need to take into account to make sure that user ...


1

As I see it, you have several solutions. It all depends on whether you want a permanent one or a workaround. A permanent one would be to update your invoice table and replace the field invoice_number with something like: CONCAT(company_id, ‘-’, invoice_number) Now, if you want a workaround, you might change your data selection query to something like ...


1

W3Schools example tutorial has the date. So its a copy paste and the developer forgot to update the expiry date.


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