Tag Info

New answers tagged

5

Procedural knots As I progress with time, I notice that it's quite difficult to navigate in my files and search where particular functionality is coded. This is the classic problem with procedural programming. Code is written where it's needed at the time the need was discovered. This leads to spaghetti code, which is an apt metaphor but alternatively ...


2

Your use case is this (please correct me if this is wrong): Users post updates. Users can have subscribers. Subscribers see the updates, and can filter based on which ones they have not seen before. Your data model then should not contain a notifications table listing the notifications per recipient. The data model would look like this: Users ...


5

Don't insert the 2000 rows when the user posts something. Instead, send a message thru a a message que saying "New post, ID is x". Then have a background process take the message off the que and process it, including generating notifications. Basically, you return a web page to the user ASAP by only doing the essentials and then do all the heavy work on ...


0

You can able to greatly increase the speed by putting your inserts inside a transaction. You can also move your prepare and bind statements outside, if you need so. The idea I generally use when working with transactions looks like this (semi-pseudo-code): try { // First of all, let's begin a transaction $db->beginTransaction(); // A set of ...


1

The original context for the meaning of MVC was as an "Object-Oriented Architectural Design Pattern". In other words, the way in which it was conceived was as a way of writing applications that were written in an object-oriented programming language running in a shared memory space in a single process on a conventional computer operating system. The reason ...


2

For a system which can handle >2000 users, adding 2000 records to a table should not be much of a problem, otherwise you have chosen the wrong hardware. If the one or two seconds block your main process for too long, add the records asynchrounously in a separate thread or process. And if you have concerns about getting too many notification records in that ...


-1

You can query which projects or task have changed? -->Yes Then I would iterate over all this items, extract the users and build an inmemory-table, where for every user the changed items are registered. Then I iterate over the users, get the items I want to add into the mail, build the mail and send it.


5

If you hate PHP so much, you should avoid developing web applications to be hosted on PHP servers. Even if there would be any SDKs (and I don't know any), you would still need to to spend a great amount of time reading PHP—for example when debugging the application. The same applies for language translators or supersets. A few years ago, I was working on a ...


0

Not as such... At least, none that I can find/think of. However, docblocks commonly follow a distinct format/pattern: /** * Summary * [optional blank line] * Description * [optional blank line] * @see Optional, but more documentation can be added here * [optional blank line] * @todo: Development docs here * [optional blank line] * @api indicator of ...


-2

The answer is to use regular expressions. I asked this question because was a little bit confused with examples: they all use one-lined regexps and test string. As stated on http://ua2.php.net/manual/en/function.preg-match.php (Example #4) PHP's preg_match actually supports a "named sbpatterns": preg_match('/(?P<name>\w+): (?P<digit>\d+)/', ...


0

Yes, don’t use generic names unless this would result in ugly code, such as 600 menu item functions. In practice, it depends. If the function really is generic - it doesn’t have any if-statements for logic that depends on the kind of menu item - then addMenuItem is a good name, because that’s what it does. If the function contains menu item-specific ...


0

First of all, using too many <script> tags that link to or refer to any other file is a bad practice. Because the more the number of link to external resources, the more will be your http request which will slow your website down. When a site is launched to production environment, generally all the different css files are merged into one (keep in mind ...


0

If your database class is responsible for getting data into and out of your actual database, then it should take care of defending against SQL injection attacks or, if you're still building dynamic SQL, escaping character sequences that can be harmful (e.g. single quotes, line breaks (in some cases), etc.). That way, everything outside of the database ...


0

Your database validations should happen in your model. Assuming you are not using a framework you can write a generic wrapper class with your CRUD operations and protect against SQL injection etc. here. Data validation can occur within your wrapper and more specific validation (e.g. like Rails like validates_presence_of) on data can occur in models that ...


1

Think about the level of abstraction. A developer who uses AuthenticationService class doesn't care if, under the hood, the class is using cookies, session, database or some magical parameters within an URI. It makes sense to have both findLoggedInUser() and loginUser() in the same class. The class itself, on the other hand, relies on a lower abstraction: ...


2

A View should not touch cookies. The place of the stored data (cookie, database, user table) is an implementation detail that a view should not know about, basically a CRUD object. Also registerUser($email, $remember = false) is not a good method signature. What if you have to pass more data for one of the cases later? This is hard to extend. Write ...


3

The sigil for a variable in php is part of how the system works. It conveys some information for the parser about what the thing actually is. By keeping the variables and the functions in completely different name spaces, it allows one to have variable names that are function names without collision. The without collision bit is kind of important in php, ...


3

It would probably break tons of existing code. Using the sigil means variables may use the same names as keywords, functions (built-in or user-defined), classes, etc.


3

Good obfuscators will store the mapping between original names and obfuscated names, and provide a tool for reversing this obfuscation in stack trace dumps which appear in your logs. The mapping won't ever go on the server, so no one but the owner of the code can perform the deobfuscation. This is similar to the debug symbols which compiled languages use ...


5

Maintain two identical hardware/software platforms: a production platform and a test platform. When an error occurs, reproduce it on the test platform. Then, upload the unobfuscated code to the test platform and reproduce the bug again. Perform the usual troubleshooting, fix the bug, obfuscate the new code, and upload it to the production server.


2

Although the use of conjunctions often indicates a violation of the SRP, in this case it is just indicating the return value of a poor man's algebraic data type that can be one of two values, either null or a "success" value. They are using a kind of Hungarian Notation to compensate for weaknesses in the type system, namely a lack of non-nullable types. In ...


1

In my code I sometime create method pairs with names like getEntity() and getEntityOrNull(). The name makes the expected behavior clear. If getEntity() finds no entity then an exception is thrown. getEntityOrNull() will return a null. By doing this, the calling code becomes a bit clearer. If the calling code has to have an entity then getEntity will do ...


5

They are probably doing so because of naming conflicts. I assume that you cannot have two methods named getEntity, one which possibly throws an exception and one which returns null. Therefore, you have to name them accordingly. I, for one, dislike the practice of having many different ways of calling the same method unless it is performing some ...


0

Your two arguments are sound. But if they're the ones in charge of deciding the naming convention, try not to feel too bad about it being something you don't agree with. While you're at it, you should convince them not to use the "get" and "set" portions unless those methods actually do directly set or get a member variable.


1

To your first question: it is quite normal that each command contructor may have a different signature with different dependencies, so constructing the commands cannot be done fully generic. Using a DIC can indeed mitigate this. For more complex scenarios, you could also use the "abstract factory" pattern, where you have one factory class per command, all ...


7

You should definitely go with developing on localhosts (or your own separate vhosts on the server - to be sure you run the application under the same environment) and push-pull changes to the production environment only from VCS. Otherwise why use a VCS at all? Just for the fun of it and as a redundancy for tour code? Version-control systems are ...


3

I suggest you read the Git book - http://git-scm.com/book You need to commit your changes after you make them and push the data to bitbucket. Once you have done this your partner can fetch the changes from Bitbucket and merge the changes, before repeating the process. Version Control is designed to prevent you overriding each others code but you must ...


1

Let's explore the differences between using an interface vs a base class: If I'm using an interface, that means I need to also implement the, for example, connection logic for each class which wants to connect to the DB. That is a huge pain. However, if I just subclass a base class (which already provides connection method), then I don't need to keep on ...



Top 50 recent answers are included