Reputation
10,299
Top tag
Next privilege 15,000 Rep.
Protect questions
Badges
4 36 50
Newest
 Enlightened
Impact
~241k people reached

17h
comment What's the right way to approach validations?
Really the type of error message should not be relevant for such a design decision. In worst case I would limit the validation error messages to strings with error codes and then add different helpers for API and UI that 'translate' those codes into real text.
17h
comment What's the right way to approach validations?
@RobertHarvey you can write arbitrary code for validations. There are basic validations for size, data type, existence of related records etc, but you can easily add complete methods for more complex validations. So the question would be mainly about those validations being in other places. Like the controller? This seems wrong. Even if you decide to have different validations for the API and the UI you should still put them into the model area.
17h
comment What's the right way to approach validations?
The validations should ensure valid data, this includes basically everything that possibly could go wrong. So: yes, the model is the place that ensures that only valid data goes into the database. That's at the core of the MVC model. You can not really depend on the UI for validations, especially in the browser the user can turn those off anyway and send any data he likes (don't trust the browser!). Also any other place would mean you would possibly duplicate validation code. In general the model is 'best practice' for all validations.
17h
comment What's the right way to approach validations?
I do not exactly understand your problem. Anyway: The ActiveRecord validations main goal is to actually ensure data integrity. It doesn't matter where the data comes from, it's on the model level, so part of the business rules. Also what's the difference between 'validating user input' and 'ensure data integrity'? You validate user input to ensure data integrity. (Data integrity being a bit of a broad term, meaning basically 'valid data'). What additional 'features' does your API have that are different from the normal user input?
20h
comment Auto Moving Objects using Java
You could just put 'java animate image' or 'java move image' in google and get lots of answers like these: stackoverflow.com/questions/14432816/…, stackoverflow.com/questions/16039768/… There are complete game tutorials available for Java.
21h
comment Why is 'continue' the keyword for skipping the rest of the loop iteration?
Well, to use continue just to do what you would do anyway would make it an empty statement. So of the two possible meanings at this place inside the loop we are left with only one that makes some more sense. I personally prefer next too, but somebody had to make a decision at the time and to his language understanding continue made enough sense. Maybe we could even discuss the use of next. Is it really the best word? Would it not just mean to continue with the next statement (another 'empty' statement then). Shouldn't we use skip? Should we use with or each instead of for?
21h
comment Why is 'continue' the keyword for skipping the rest of the loop iteration?
Maybe the idea is that the loop as such is kept running, compared to the break statement that would stop the whole looping.
Jul
22
comment Ruby Constructor
The link from MichaelT already provides a few points, though the question is rather old, so now Ruby also has keyword arguments (named params), so you can have several param options and just 'fill in' those you need and either ignore the others or provide useful default values.
Jul
22
comment MVC is a kind of Design Pattern?
It's sometimes named architectural pattern, so a bit more high level than your common OOP design pattern since it works on the whole project structure and not only a single class (or small group of classes).
Jul
20
comment How do services like payment gateway handle concurrent database queries?
Transactions and record locks mostly. Question is a bit unspecific, so difficult to go into much detail without writing a whole tutorial on the matter.
Jul
20
comment Best practice for buffering when posting to a web-service that has gone offline
Would depend on amount of data, data format (CSV, binary, JSON, XML...) and maybe a few other factors (also considering using another service if this one isn't reliable enough, though of course may not be an option for whatever reasons). There are various simple solutions for log data that could handle this maybe, one thing to look into could be the Elasticsearch ELK stack.
Jul
20
comment How to deal with stock updates when a user makes a purchase in e-commerce?
You either have the basket in your database or the 'pending purchase' table you mentioned. In any case every record has a timestamp, so you can simply add all records for a given article that are not older than 10 minutes (or whatever) and subtract that amount from stock. A lot depends here on amount of customers on your site and how often this really happen (chances are less often then you may think). If this becomes a serious problem (you should log as much data about this as possible, especially if you show customers 'out of stock' messages) you should consider to stock higher volumes.
Jul
20
comment How to deal with stock updates when a user makes a purchase in e-commerce?
@skirato I was just basically writing a comment repeating my answer for the question MetaFight linked. Didn't even remember I ever answered it there.
Jul
8
comment REST API paging via headers
This still is more complicated and not the standard. I just fail to see why you would want to do that at all? There seems to be no real advantage to it, only makes using your API more complicated. As it is now you will have libraries that can easily make GET requests (also you can easily use command line tools like wget or curl for testing your API) and all you need to do is concatenating a simple string into the correct URI with all params. All this without worrying about how to get your tools to change header info. It's simple, it works, so you should have a very good reason to change it.
Jul
8
comment REST API paging via headers
This would be a bit uncommon. The range is more for data requests like getting part of a video file (e.g. when you click the progress bar in a youtube video). To start with in most cases it will be just more complicated (at least require javascript) to get this working. Also it would make it more or less impossible for search engines to follow you links, so you would possibly have negative SEO effects if that is relevant to your site.
Jun
22
comment php - design: database operations
yes, a framework would be a good idea. Once you worked with one you will get the idea. At least for tasks like those it will give you all you need (beyond that you would have to look into 'design patterns' and OOP but this is a larger thing.). Confusing to me is that if some of those if conditions fail, you still do return $row while no value was assigned to it (which happens only deeper inside those nested if/then).
Jun
22
comment php - design: database operations
Hmm, something model-view-controller would be the way to go I guess. What you describe would be a very simplified approach to a model layer which would already be a step ahead to separate your business and database model from the rest of the app. (Also unrelated: I am no PHP dev, but those functions look quite confusing and seem to return $row in various situation without assigning a value to this variable. Maybe guard clauses would help clean that up a bit by avoiding to nest if/then statements too deep)
Jun
19
comment Client and access to Github history
We do have access to the repositories of our outsourced projects. So that's definitely nothing like 'no developer would ever...'. But to be true, we learned the hard way to make this part of all agreements. From a legal point in your case this may be a matter of interpretation of the actual contract, 'all material' may be seen as 'results only' or really everything. In any case if it's needed as evidence for a law suit a lawyer may be able to get it even if it's not seen as part of the contract.
Jun
16
comment Web apps for enterprise
We did a prototype like that with something called Phonegap. The storage as such worked well enough. Syncing is tricky but can be solved (depending on complexity of the data). But for our case we run in some usability and performance trouble and finally decided for native (which was an easy decisions, since our employees all used the same product). There are limits with html, especially things like background synch and native features like push notifications or whatever are missing.
Jun
13
comment Best way to handle blank dates
This really may depend on your application. In some cases it may work or make sense to set an arbitrary date for unknown (say 31.12.1799) in others this may lead to difficult to track errors, like if you need to decide if somebody is of full age to make a purchase.