Tag Info

New answers tagged

1

You compile each source file into object files using the appropriate complier for its language, then link the object files into an executable, the same way you would for any other program. For this to work, all the compilers have to agree on how the modules communicate with each other. This includes things such as: what symbol names the objects export and ...


2

Notice that a complex program does not need to be coded in several languages. For example, the Linux kernel is a complex program (of more than ten millions source lines of C code with a bit of assembly). Then, mixing multiple languages is implementation specific (often related to foreign function interface) but most language implementations offer the ...


0

I don't think the problem lies with where to store use activities but how you're planning to store them. If I've correctly read your comments, it seems like you could accomplish the same thing far more easily if you define a table for each type of activity. For instance when storing a record of purchased games, have tables for games, users, and ...


0

It seems to me like you are implementing something like event sourcing. In a typical event sourcing framework a class is serilized to text I.e json before it is appended to db. To answer your question. The user activities should be defined in code as a class.


0

This blog post shows the results of a performance comparison of different session storage engines with Magento and they seem to have concluded that up to about 75 concurrent users there isn't really a performance difference between them. I think that at these levels (they had about 5 transactions a second, which would be about 430k hits over a 12 hour ...


2

In PHP the foreach loop creates a temporary variable storing the initial array passed. you can pass $value by reference using &$value. In the two examples below the loops remove the next element in the array. Since it is a temporary variable changes to the original have no effect on the foreach loop. <?php $arr = array(1,2,3,4,5,6,7,8,9); ...


0

The technique you're looking for is called two phase commit. Essentially, the idea is that you ask each of your services to determine whether the transaction will succeed or not, then you separately tell each of them whether or not to actually proceed with the transaction. They may have to lock resources during the preparation phase in order to ensure the ...


4

Whenever a database has multiple concurrent writers, there are potential race conditions. In particular, if each writer tries to add a new row, they may all choose the same primary key if they're just doing max(...)+1, and then all but one of the inserts will fail. When a database has an "auto increment" feature, they're not saving you the trouble of ...


3

First of all, I wouldn't approach a clean architecture in PHP. One of the main goals of clean architecture is to allow the user interface to be considered as essentially a plugin to the application, allowing you to change between types of UI easily. By going with PHP you are restricting yourself essentially to web-based interfaces. If you are familiar with a ...


5

I would agree that this is not a good idea. Even if the language you're using defines what should happen in this situation (I don't know if PHP does; that's a question for StackOverflow) most people who see code like this would still have to look up whether or not it's defined behavior before they could have any confidence in it. If the list of desired ...


0

Did you look at role-based permissions? One controller, one route, returns/accepts different results depending on a user role. E.g. a GET request to http://blah.com/tickets will return all tickets if requester is an admin, or user's own tickets otherwise. A post to this route will return 200 for user, but 40x error (405 would fit here, I think?) for ...


0

Registering multiple autoloaders lets you separate different naming conventions for directory and file names and will be easier to maintain in the long run. Imagine needing to add or remove functionality for the autoloader. Should you need to dive into a monolithic function or simply tweak or add a smaller function? Similar calls to "file_exists() / ...


11

The problem you are addressing is quite fundamental. I have experienced the same problem when I worked for a company that made a large J2EE application that consisted of several hundred web pages and over a million and a half lines of Java code. This code used ORM (JPA) for persistence. This problem get worse when you use 3rd party technologies in every ...


7

The problem you facing is an old one: code for persistent objects often looks similar for each class, it is simply boilerplate code. That's why some smart people invented Object Relational Mappers - they solve exactly that problem. See this former SO post for a list of ORMs for PHP. When existing ORMs do not suffer your needs, there is also an alternative: ...


0

OK in PHP "SESSION" is an illusion. Every interaction between the browser and the web server is a single atomic transaction unrelated to any other interaction. The "SESSION"mechanism gives the illusion of a "connection" by passing a cookie to and from the browser and storing some variables locally at the server. You can end a SESSION the the ...


4

The service shouldn't make any decisions or you end up with a anemic domain model. Your license aggregate should make the decisions. If the license aggregate needs to call a web service you pass an instance of a helper for that service to the method on the aggregate. It can them choose to use them if it so wishes.


0

I agree with @BartvanIngenSchenau : add the validate inside toString. Also: toString would be much better be renamed to build, to more strongly suggest a Builder Pattern. Unlike C#, in PHP the convention is to NOT use the letter I in interface names getters are not necessary maybe mark the validate method as private. From what I now, in the context of the ...


2

The important thing is to distinguish between TDD and ATDD. The AT there stands for "acceptance tests", and this refers to development where you first start with an acceptance test, which is likely to test the entire stack. This is also sometimes called "outside-in test driven development". When people talk about TDD, the "T" there probably refers ...


7

Is there a technique for unit testing both components in one run? That would actually be the opposite of unit testing - unit testing, especially in TDD style, means to test your components in isolation. Thus the answer is yes, "run separate test suites for the JS and PHP sections", otherwise it is not unit testing and not TDD. Of course, automated ...


2

Keep your DTO's simple You are right that having a command with 9 arguments in the constructor is ugly. But do you really HAVE to put those things into the constructor? Make your fields public, create your command with an empty constructor and just assign to the fields. The point of constructor arguments is to have guaranteed valid entities, since you are ...


-2

This is the GUID format. Please find the sequence of 32 hex digits grouped into chunks of 8-4-4-4-12. This proves your url consists a GUID. Read More about GUID here. If you are going to use GUIDs as your product identifiers, please research about it. There are debates over performance issues. No one is going to encrypt their id fields.


0

In my app, the logic flow goes Controller builds DTO Controller dispatches to Command Bus Command Bus Calls Events Event Handlers dispatch to the Command Bus as well Command Handler returns a response DTO to the controller Controller generates a response to the client based on the response Your application seems similar. Decoupling is also an issue for ...


8

Attempt to fetch the user record based on the username (but use LIKE instead of = so that case doesn't matter. Usernames should not be case sensitive. If you managed to fetch a user record (then the user exists) and you can compare the passwords to validate the login. About password security Store the passwords using a function like password_hash() so ...


2

Typically I'd just search the table for the record that contains the matching username. If that record doesn't exist the user doesn't exist so there is no need to go any further. If the record does exist that record would have the password hash on it for that user. Take the password given by the user, hash it in the same way, compare to the hash in your ...


-2

Developer Documentation How do I (as another developer) know that this has been tested? If I want to fix a bug in the self contained function, how do I know that I am not introducing a bug that you had already considered? Complexity indicator: # of tests can be a good measure of how complex something is. This may indicate that you shouldn't touch it ...


2

Most dependency injection containers can be configured to create the dependencies as well as inject them. No need to have a separate process to create dependencies. Here is a simple example using the PHP Pimple container(http://pimple.sensiolabs.org/) // This is the importer service definition $dic['arbiter_schedule_importer_games_with_slots_xml'] = ...


2

Reality Check I have been in challenging environments where testing is "a waste of time" during budgeting and schedule, and then "a fundamental part of quality assurance" once the customer is dealing with bugs, so my opinion is more fluid than others might be. You have a budget. Your job is to get the best product you can on that budget, for whatever ...


0

Yes, keep the tests, keep them running and keep them passing. Unit tests are there to protect you (and others) from yourself (and themselves). Why is keeping the tests a good idea; Validate the previous requirements' functionality in the face of new requirements and additional functionality Verify that refactoring exercises are correct Internal ...


43

Because nothing is so simple that there can't be bugs. Your code, while on the face of it looks to be bug free. It is in fact a simple programmatic representation of a polynomial function. Except it has a bug... public function polynominal($a, $b, $c, $d) { return $a * pow($x, 3) + $b * pow($x, 2) + $c * $x + $d; } $x is not defined as an input to ...


12

Everything said in the other answers is correct, but I will add one more. Documentation Unit tests, if well written, can explain to a developer exactly what a function does, what its input/output expectations are, and more importantly, what behavior can be expected of it. It can make spotting a bug easier and lower confusion. Not everybody remembers ...


76

Regression testing It's all about regression testing. Imagine the next developer looking at your method and noticing that you are using magical numbers. He was told that magical numbers are evil, so he creates two constants, one for the number two, the other one for the number three—there is nothing wrong in doing this change; it's not like he was ...


20

Yes. If we could say with 100% confidence, with certainty: this function will never be edited and will never run in a context which could cause it to fail - if we could say that, we could drop the tests and save a few milliseconds on every CI build. But we can't. Or, we can't with many functions. And it's simpler to have a rule of running all the tests ...


2

The answer to your question, that number you are seeing is called a GUID. Its a number format that can be generated quickly, and is mathematically just short of being guaranteed that neither yourself or anyone else will generate a new guid, with the same value. It is quite likely that this is used as the identifier in the database record for that product. ...


0

I would avoid doing this in PHP. You are going to hit a number of fundamental problems: the limit on concurrent requests on your clients browsers won't let them have 21 simultaneous requests open the connection limit in your web sever won't handle the incoming requests very well if you have more than a handful of concurrent users multithreading at the ...


0

If you are not familiar with threading, you could also use php to start a number of individual copies of the same program on the backend such as a linux box. Each of these would execute and could write their contents to uniquely names files in a directory. You could then collect the files as they were completed counting until you got all 21 files or you ...


4

Okay, first things first: you're running PHP 5.2!? There's not really much reason to stay with that other than having out of date servers, and that means it's either time to switch hosts or update your servers because PHP 5.2 has some major known security holes which aren't ever going to be fixed. This'll also give you access to a bunch of new features, the ...


1

I agree with Snowman, but as to not leave you empty handed, I will discuss a few possibilities. If by 'doing the front-end work', you have primarily been tasked with designing the project, then you can design the site according to your normal workflow and simply pass it off to him to integrate it. If you are responsible for everything client-side, then you ...


1

Your best bet for this if your intended clients have sufficiently modern web browsers is Web Sockets. There are plenty of libraries out there that you can use and can look into. The one I have used most recently for PHP projects is Pusher, but searching for 'PHP websockets' turns up plenty of libraries and code samples you could use.


4

After some investigation, I would say this seems pretty optimal. Please see my gist here. In the PHP file in the gist I've generated some nested arrays with unsorted keys using one function, counted the total number of keys (including keys in nested arrays) using the recursive option to count, timed sorting the array using your function above, generated a ...


-1

I think it depends. If you are just using a little bit of PHP to create a list via looping, it makes sense to put it in the HTML. If your PHP is extensive and is generating the bulk of the HTML, it could make sense to do HTML within PHP.


4

What about: Neither Mixing languages is not a good idea. You don't put JavaScript in HTML, or HTML in JavaScript, or JavaScript in PHP, or HTML in Python or Ruby in SQL. Why don't we do that? Because different languages usually correspond to different layers. PHP deals with business logic. HTML deals with presentation of the business objects. Thus, you ...


0

The most readable is php in html but only a little. You should split your file in two parts. Logic in the top. Here you prepare all variables but no html. In the bottom you put html with variables and a loop or two but little to no logic. Of course this doesn't scale all that well. For larger projects you should probably use a mvc framework.


1

You would have a better chance of resolving Sunni/Shite differences than you will of getting a clear answer to this sort of question. For myself, I like React's notion of components and PHP s heredoc syntax. class CompanyComponent { public function __construct($company) { $this->company = $company; } protected function ...



Top 50 recent answers are included