Tag Info

New answers tagged

0

In the end I decided on option 4. Have the interface specify that getAmount() can throw an exception, and have the BigAmount implementation throw one should it not be possible to express its value as an integer. Then I'll have another method that can return the amount in another format. It would require the programmer using the class to jump through some ...


0

In MVC it's very uncommon to have a single model or controller. It is however common to have one or very few view "flavors" which all render templates differently. Each controller should have a single purpose, whether it's routing, or applying business logic to a model. You should route the request to the appropriate controller for each model, ideally ...


0

Using PHP you would access the current user SessionToken cookie stored when you authenticated the user to check if: There is one present It has not passed its expiry It is the current token for that user stored in a session database I would implement this by writing the code in a separate file/module and include it into each page of your project or main ...


0

Have a history table storing all updates like in Wordpress with a version number. Yes, but store not updates, but complete revisions (contents of each edit). If you need to save space, compress it. But don't care too much about the size. Humans are rarely capable of producing large volumes of data by themselves. There are many libraries, that can ...


0

It is much more common to use url parameters. For example: example.com/index.php?page=1 example.com/index.php?page=2 Then on index.php you can use $_GET['page'] to figure out which page you are retrieving, then serve that data. If you are actually generating php files on your server you can serve that page using: include 'page2.php'; Or even better: ...


19

This is entirely possible. Let's assume we have 35 switch-case constructs of 10 cases each, which would give us a rough cyclomatic complexity of 350 when each switch occurs one after the other. The first switch gives us 10 paths. The second switch gives us another independent 10 paths, so that we have 10ยท10 paths until here. With the third switch, we get ...


4

According to this description, NPath complexity is exponential in cyclomatic complexity. Taking just simple if statements, if you have two of these statements, that's essentially 4 routes through your code corresponding to the four possible combinations of true/false for the two statement conditions. Add another if statement and you get 8. In other words, ...


1

The answer to this question "are mocks in unit tests dangerous in dynamic languages?" is "Hell yes!" The following article explains the dangers. They describe a scenario where an interfaces method name changed. For example, changing a methods name from error() to errors(). If we are mocking the error() method in our tests, they will never turn red to alert ...


0

is there any way to mitigate the risk of incorrect mocks and implementations? In python-mock, you can specify a mock spec. A spec constraints what methods and attributes are available in the mocked object, thus you'll get an error if the system under test (SUT) try to call or access something unexpected. My concern is what happens if we accidentally ...


1

Before I start I will add come context to question to highlight the problem. Consider: class SUT { public function tested(MyInterface $x) { $this->hidden($x->myMethod()); } protected function hidden($x) { $x->aMethodOfSomeObject() } } //Somewhere in test: $sutInstance($myInterfaceMock); Now. Your MyInterface::MyMethod returns ...


0

I'd say that mocks are dangerous in every language. Let's say that I call: priceCalculator.calculate( qty, item, isPlusCustomer, isSenior); What if: isPlusCustomer and isSenior are supposed to be in the other order? qty was supposed be a weight, not a qty. you needed to initialize the priceCalculator first before using it? There are ...


1

You don't have to test for the correct return type in a dynamically-typed language, unless the method is specifically designed to return a specific type (i.e. a Factory). Rely instead on other kinds of tests that are more meaningful from a program logic perspective. To give a simple (and admittedly contrived) example, if I expected a method to return a ...


0

It sounds very much like Paypal payments are processed. Paypal allows for sandbox accounts purely for testing purposes. Here is the link to Paypal testing guide I heard good things about it from my friends.


3

This rule and consequent warning is sensible - I definitely wouldn't like to see class/constant definitions mixed with side-effects in one file. But in this particular case I wouldn't mind - PHP bootstrap files are usually a bit like this - setting up the environment which sometimes consists of several distinct (and possibly unrelated) steps. You could ...


0

Merging in SVN is no different to merging in git - if the computer can figure it out, it does it and all's good, if it needs manual attention it prompts you. (exception: SVN's handling of new/deleted/renamed files is poor, but git can have issues in this area too). So, that out of the way you can really think of SVN as a clone of a repo that you push to. ...


0

Practical URL length limit is around 2000 characters - think about whether you could optimize you filters to fit into it. It this is not possible I'd probably implement this as a POST request. Disadvantages: although this is in line with HTTP semantics of POST request (POST can be used for almost anything), it's not a best fit - it's effectively ...


1

If you want to preserve data across the pages, there are several approaches: The URI or the form. A wrong choice in most situations (some ASP.NET developers would disagree, pointing to view state as an example of preserving information in a form). Sessions. This works well for most cases if the size of the preserved data is not very large. Database ...


5

So if a thousand people are following Sally, we insert a thousand rows into the corresponding table. Is that scalable? Yes, provided the database tables are properly indexed. What happens if we get to the point where tens or hundreds of thousands of users are following Sally and she's making a few dozen posts per day? You'll generate a few dozen ...


-2

Answer is always Use normal queries instead of ORM to get better performance. If your are planning to change the database after some longer period ORM helps to done easily.You need to sacrifice performance for convenience. I suggest you to create the separate class where you can perform DML operations by getting the inputs as parameter and create the query ...


1

Since you are not developing a website or a web application, but a desktop application which stores its data on a server, there are indeed a few layers you can skip. A common approach, in this situation, is to use web services. When a service should be lightweight and interoperable (that is, you can use it with ease from virtually every programming ...


1

Yes it is. DuckDuckGo is one company that I know of that started with Perl as the server side language. I believe they are still using Perl primarily. https://github.com/duckduckgo


2

Some people still use it (I'm one of them). So, it hasn't been replaced. In fact, I switched to Perl from PHP.


0

PHP, in my opinion, is a much faster and better choice for the web. We also have Javascript, which is blazing fast due to it's event-based nature. However Perl is still used and there are web frameworks for Perl in web use such as Catalyst. There is also an emergence of Python being used in the web. Frameworks such as Django, which I have had personal ...



Top 50 recent answers are included