News for hackers. Stuff that matters.
Re:Should "Yes, delete it" be red, or green? by comex on Wednesday March 26, 2014 @11:00PM (#7478307)
Neither. Wherever possible, design your code to use undo rather than confirmation, Gmail-style. Saves the user time and avoids training them to click through confirmations (and perhaps eventually be sorry).
Re:Should "Yes, delete it" be red, or green? by qq66 on Wednesday March 26, 2014 @11:57PM (#7478504)
Making an action undoable often more than doubles the development cost of that feature. Google can do it, for a small startup it only makes sense in a few situations.
Re:Should "Yes, delete it" be red, or green? by MarkMc on Thursday March 27, 2014 @12:09AM (#7478549)
It is particularly difficult in a collaborative application with 'hard' links between records. For example, consider this scenario:

(1) Sally deletes an employee record

(2) Bob deletes that employee's department

(3) Sally tries to undo the deletion of the employee - will the employee be restored without a department?

Re:Should "Yes, delete it" be red, or green? by hueving on Thursday March 27, 2014 @02:36AM (#7478943)
>(1) Sally deletes an employee record >(2) Bob deletes that employee's department

I would argue that a good design would actually prevent you from deleting important records like these. i.e. when Bob clicks delete, it just marks the object as deleted and it stops showing up in reports/interfaces. Then maybe you have something clean it up 90 days later or something.

Re:Should "Yes, delete it" be red, or green? by ajuc on Thursday March 27, 2014 @02:51AM (#7478976)
Yes. This is pattern I've seen in both companies I worked for, and it makes so much sense.

Similairly you don't make table ARTICLES with column AMOUNT and KIND. You make table CHANGES with DIFFERENCE and KIND, and only ever add rows to that table (possibly with negative DIFFERENCE).

Re:Should "Yes, delete it" be red, or green? by pc86 on Thursday March 27, 2014 @10:24AM (#7480550)
Sorry I don’t really understand what you’re trying to say here. Could you expand on the differences in data between the two tables, please?
Re:Should "Yes, delete it" be red, or green? by Xlythe on Thursday March 27, 2014 @11:45AM (#7481072)
In the first case, you only know the AMOUNT. You can't undo transactions because you only have 1 object stored, the total amount. If you store DIFFERENCE, then you'll have a table of every transaction and can undo them individually. The cost is having to sum the table whenever you want to know the amount (which is usually worth the flexibility).
Re:Should "Yes, delete it" be red, or green? by ajuc on Thursday March 27, 2014 @12:48PM (#7481605)
Regarding the performance - you can add triggers writing to additional table with a sum, or maintain that table in the code that adds rows, or calculate it each time you want to know the sum.
Re:Should "Yes, delete it" be red, or green? by rehack on Thursday March 27, 2014 @11:52AM (#7481104)
This is what I understood (s)he means

Scenario: Laptop's price is initially $800 and then increases to $850 before dropping to $825

Design 1: with columns Amount and Kind will just have a single row which will get modified with the latest value

Design 2: Will have 3 rows in the above case

Difference | Kind | Time stamp

800 | 'Laptop' | ts 1

+50 | 'Laptop' | ts 2

-25 | 'Laptop' | ts 3

So this latter design has 'undo' builtin

edit: formating

Re:Should "Yes, delete it" be red, or green? by ajuc on Thursday March 27, 2014 @12:46PM (#7481587)
Yes, that's what I've meant. This also gives you easy accountability (rows can have information like user_id, ip, timestamp).
Re:Should "Yes, delete it" be red, or green? by rangibaby on Thursday March 27, 2014 @12:21AM (#7478594)
Intuitively, I would expect it to restore both the department and employee, or throw it into a "Bob and Sally: Please fix this conflict" kind of box.
Re:Should "Yes, delete it" be red, or green? by NovaS1X on Thursday March 27, 2014 @02:33AM (#7478938)
I'd expect it to depend on the permissions of the user restoring or deleting the groups.

Under complete presumption: Bob is an HR member while Sally is a Manager. Why? The ability to manage entire groups should be left to people higher up in the administration chain where individual users should be delegated to HR or other staff.

Bob should have permissions to manage users but not groups. Sally should have permissions to manage both. If Bob deletes a user, then Sally deletes the group, there should be no reason that Bob should be able to anything outside his domain. The group should not be restored and Bob should be given a clear, 'plain English' reason why he can't do such an action.

If both Sally and Bob are managers of a group and said situation occurs, no group should be restored when Bob restores a user. Only a readable error message should occur. In fact no data to be restored should be there in the first place unless it has been backed up or cached.

What is a possible solution to this logic?

1.) You could implement an optional backup system. All deletes are final in the context of the action. Think of a common tree structure: if no main branch is there to support a twig then no twig can hang. No restores via users can be performed until the group has been restored. The deleted data could be stored in a cache until certain parameters are met; once these are met the data is deleted (IE: Recycle Bin)

2.) Users could be restored belonging to a default group. If a recently deleted member of a recently deleted group needs to be restored, they could be assigned to a default 'holding' group or other similar group with restricted permissions. This retains all specific user data which is not lost and by default the user will not be given extraneous or extra permissions. They can then be assigned to an appropriate group.

3.) Removing a group does not affect users within it. This is the opposite of a tree structure. This is analogous to Linux group and user permissions. A group can be assigned to users so they can access a resource. They are not interconnected in any way other than their usage to control permissions. Users can be removed and restored at will and so can groups. No conflicts of hierarchy are incurred.

In summary, restoring an individual resource should never restore the controlling body without given consent. This would create a lot of problems if it did.

Re:Should "Yes, delete it" be red, or green? by dirtyaura on Thursday March 27, 2014 @02:28AM (#7478930)
Yes, it gets complex fast in collaborative setting. To my understanding, there are two robust approaches to collaborative editing:

- git-style 3-way-merge

- Google Wave -style operational transform

If somebody is experienced on the topic, I'd love to learn more about different approaches. Also, it would be awesome to have these as an open source DB projects (well, we have git) or even offered as IaaS.

Re:Should "Yes, delete it" be red, or green? by troym on Thursday March 27, 2014 @03:36AM (#7479082)
(3a) No, because your data model never allows physical deletes. (3b) And because you modeled up to 6NF with temporal keys, you've got the record from (1) and (2) and you know at what times they were related.
Re:Should "Yes, delete it" be red, or green? by antimagic on Thursday March 27, 2014 @05:27AM (#7479339)
If Bob truly has the authority to decide that the entire department can be deleted from the database, and if the employee record really does have a dependency on the department, then the correct response is either: a) Sally's interface has already updated to reflect the fact that the department has been deleted, so she doesn't even have the option to delete anymore b)(where realtime updating of the interface isn't possible) - when Sally tries to modify the deleted record she is presented with a message stating that the action failed due to the department having been deleted by Bob. Sally can now either undo Bob's delete first (or ask Bob to do it), and then undo her own change.

User confirmation dialogues are a UI smell, in the same way that a module of code stuffed with if statements and flags is a code smell. It's telling you that your design has a fundamental flaw that needs to be fixed in a non-trivial way. Just t hink about the basic question - should red be "delete" or "no". Either way, the question implicitly recognises that this situation is confusing, and that Sally has a good chance of making a mistake. Knowing that her problem has arisen because she clicked on the wrong button ("when it was clearly coloured red!") is not going to make Sally like your software. Make it so that she can fix her error, not so that she doesn't make the error in the first place.

Re:Should "Yes, delete it" be red, or green? by mbesto on Thursday March 27, 2014 @12:52AM (#7478674)
I 100% agree `Undo` is the best way to go about this. Equally, I'm very curious to hear how others have implemented this in their app. The complexity for such a small feature is actually quite high, because we start playing with the database (and therefore, in many cases a robust ORM)

Anyone have experience with doing something like this in Rails?

Re:Should "Yes, delete it" be red, or green? by ericingram on Thursday March 27, 2014 @01:12AM (#7478733)
We solve it using an "archive" collection in mongodb. Deleting moves a document from one collection to the archive, while undo moves it back.

We also implement ability to find deleted documents by id, by searching the archive if the record is not found in the original collection.

API looks like this:

    // delete something
    delete("/products/123")
    
    // see it in the archive
    get("/archive/products/123")
    
    // undelete it
    put("/products/123", {$restore: true})
Re:Should "Yes, delete it" be red, or green? by ForHackernews on Thursday March 27, 2014 @01:12AM (#7478734)
One simple implementation is just to queue up the action without committing it, then "undo" actually just cancels a pending action. The downside of this approach is "undo" becomes a limited time only offer.
Re:Should "Yes, delete it" be red, or green? by weavie on Thursday March 27, 2014 @04:51AM (#7479251)
I just stick an isDeleted column on my tables. It does mean I have to remember to do a `where !isDeleted` on all my main queries, but apart from that the cost of undoing is incredibly cheap.
Re:Should "Yes, delete it" be red, or green? by runner84111 on Thursday March 27, 2014 @02:21AM (#7478910)
Actual deletion occurs on app close (or next open). The "delete" the user sees just hides the data.
Re:Should "Yes, delete it" be red, or green? by grn on Thursday March 27, 2014 @03:30AM (#7479063)
But you can still mark the buttons with colors so your users will make less mistakes. I think that the two issues are orthogonal.
Re:Should "Yes, delete it" be red, or green? by new_guy123 on Thursday March 27, 2014 @01:35AM (#7478807)
It doesn't - the undo action is not a permanent option since it is only a replacement for a yes/no prompt. The implementation then could be a delayed action. Might not work for all use cases, but good enough for most, especially in a start up situation.
Re:Should "Yes, delete it" be red, or green? by SixSigma on Thursday March 27, 2014 @03:56AM (#7479119)
Saving dev costs by making your users pay with their data loss is extraordinarily short sighted. If you cant code with an undo feature, perhaps this is not the discipline for you.
Re:Should "Yes, delete it" be red, or green? by raldi on Thursday March 27, 2014 @12:00AM (#7478514)
How many situations does the small startup have where they're going to be destroying something?
Re:Should "Yes, delete it" be red, or green? by diminoten on Thursday March 27, 2014 @12:08AM (#7478545)
When your startup allows users to create categories or unit groupings, maybe?

Removing credit cards, as well.

I dunno, do you really think it's rare for startups to be deleting data?

Re:Should "Yes, delete it" be red, or green? by raldi on Thursday March 27, 2014 @11:40AM (#7481034)
I think they delete data all the time. But I think there are just a small number of situations where it happens.

For example, someone on HN probably deletes a comment every few seconds. The site is therefore deleting data constantly. But all that only counts as one single situation.

Is there any other situation where an HN non-admin ever deletes data?

Re:Should "Yes, delete it" be red, or green? by diminoten on Thursday March 27, 2014 @01:26PM (#7481897)
That's a good point; I don't think I can delete my submissions or my account on here, but even then 3 total use cases revolving around delete isn't exactly a huge number.
Re:Should "Yes, delete it" be red, or green? by brandoncapecci on Thursday March 27, 2014 @01:07AM (#7478719)
CRU
Re:Should "Yes, delete it" be red, or green? by troym on Thursday March 27, 2014 @03:29AM (#7479061)
> Making an action undoable often more than doubles the development cost of that feature.

Every time I've added the feature, it's bordered on trivial (start a timer to execute the actual delete request, show a link to cancel the request, hide the DOM element).

I suppose if you were doing all the work server-side, then yah, it would be difficult. But the way GOOG does it (IIRC) it's not that hard at all.

Re:Should "Yes, delete it" be red, or green? by dsego on Thursday March 27, 2014 @05:06AM (#7479279)
That is cancellation then, not undo.
Re:Should "Yes, delete it" be red, or green? by tsudot on Wednesday March 26, 2014 @11:34PM (#7478439)
> design your code to use undo rather than confirmation

I can think of two ways to implement undo.

1. Use flags in the database, this method has its own drawback since the entry is not really deleted but flagged as one.

2. Client side. Delay the actual delete request to the server.

Re:Should "Yes, delete it" be red, or green? by MichaelApproved on Wednesday March 26, 2014 @11:47PM (#7478477)
The delete flag in the DB could be null or the date the delete was requested. You could batch the commit cleanup hourly giving a delete at least X hours before it's committed.
Re:Should "Yes, delete it" be red, or green? by tiziano88 on Wednesday March 26, 2014 @11:41PM (#7478462)
I think no one would implement it client side in practice; if the user clicks delete and immediately closes the browser, what happens to the action?
Re:Should "Yes, delete it" be red, or green? by dkuntz2 on Thursday March 27, 2014 @12:01AM (#7478520)
Do what Gmail does and say "actions are still pending" as confirm box...
Re:Should "Yes, delete it" be red, or green? by jowiar on Thursday March 27, 2014 @12:05AM (#7478534)
One standard "undo" mechanism is to store a stack of actions (per user), with each action having a method to undo itself.
Re:Should "Yes, delete it" be red, or green? by noblethrasher on Wednesday March 26, 2014 @11:48PM (#7478481)
It depends on how you interpret “delete”. Most people seem to want to make it synonymous with “erase”, but it should really mean something like “forget”. In that case, it’s easy to see how you would implement “undo”: just drop all (root) references to the record(s) in question and collect as garbage at a certain time (in, say, 30 days).
Re:Should "Yes, delete it" be red, or green? by kyllo on Thursday March 27, 2014 @12:56AM (#7478686)
Another standard way is with the command pattern, and using one "undo" stack, with another "redo stack". When you perform a command, a command object is pushed onto the "undo" stack. When you undo a command, it's popped off the stack, its undo() method is called, and it's pushed onto the "redo" stack. When you redo a command, it's popped off the redo stack, and executed. When you execute a new command (not an undo or redo) you push it onto the undo stack and clear out the redo stack.

See this SO question for further detail and links: http://stackoverflow.com/questions/701131/data-structure-use...

Re:Should "Yes, delete it" be red, or green? by darylteo on Wednesday March 26, 2014 @11:38PM (#7478449)
There actually is another way. Event-Sourcing. I've never seen this technique in my limited experience though, but theoretically this would be the optimal way to implement such a feature, and obviously has to be a engineering decision from the get-go.

Alternatively you could also have a very primitive form of version control : recycle-bin (edit: actually this is the same as point 1 =) )

Re:Should "Yes, delete it" be red, or green? by nl on Thursday March 27, 2014 @12:41AM (#7478646)
See also Operational Transform[1]. There be dragons, though.

[1] http://en.wikipedia.org/wiki/Operational_transformation

Re:Should "Yes, delete it" be red, or green? by darylteo on Thursday March 27, 2014 @10:04AM (#7480425)
I liked this part:

"Similarly, Joseph Gentle who is an ex Google Wave engineer and an author of the Share.JS library wrote: Unfortunately, implementing OT sucks. There's a million algorithms with different tradeoffs, mostly trapped in academic papers. The algorithms are really hard and time consuming to implement correctly. ... Wave took 2 years to write and if we rewrote it today, it would take almost as long to write a second time."

Re:Should "Yes, delete it" be red, or green? by jonahx on Wednesday March 26, 2014 @11:48PM (#7478480)
How would the Event-Sourcing method work?
Re:Should "Yes, delete it" be red, or green? by lomnakkus on Thursday March 27, 2014 @02:19AM (#7478904)
A useful analogy might be how accounting ledgers work. You never really delete anything; you just keep appending records saying what you've done. The balance is just the sum of all those operations. (Ledgers are a bit special in that usually all the operations in a ledger are commutative (+/-), but other than that it seems a pretty good analogy.)
Re:Should "Yes, delete it" be red, or green? by darylteo on Wednesday March 26, 2014 @11:53PM (#7478491)
First you start treating each event/operation as a fundamental part of your problem. Each Event can then have a opposite reverting Event. So if you want to reverse an action, you can just apply the opposite event. You can also display a list of recent events that have taken place easily:

  - user X modified article Z
  - user Y deleted article Z (revert?)
Note that I've only studied this in passing, and have never applied this in practice, so I can't answer just how effective this could be. Also not really sure how this works when other actions have already taken place, or how you can detect if an event cannot be recovered from (if there is such a thing).
Re:Should "Yes, delete it" be red, or green? by a_bonobo on Wednesday March 26, 2014 @11:38PM (#7478448)
Could you just delay the COMMIT for a few minutes/seconds/until the user navigates away?

And if the user clicks UNDO, do a ROLLBACK?

Edit: Of course, if anything goes wrong before the COMMIT, you loose the transaction.

Re:Should "Yes, delete it" be red, or green? by TylerE on Thursday March 27, 2014 @12:37AM (#7478635)
That's not really feasible in a real world environment where database connections are frequently re-used and user requests are very short lived.

Database transaction are like try/except blocks - designed to clean up unexpected situations instantly, not as a state mechanism.

Re:Should "Yes, delete it" be red, or green? by a_bonobo on Thursday March 27, 2014 @10:02PM (#7484855)
Thank you for the answer and explanation!
Re:Should "Yes, delete it" be red, or green? by enscr on Thursday March 27, 2014 @12:45AM (#7478655)
I've found Undo prone to failure. E.g.

- In Android's gmail, sometimes undo does not recover the message (probably a bug)

- When I'm swiping pictures in Android and accidentally delete a picture and by the time I realize, the momentum of my action has already dismissed undo.

- Gmail undo : disappears after a time span. What if I delete & suddenly get distracted by something. By the time I return, I've to dig through trash to recover my action.

Re:Should "Yes, delete it" be red, or green? by pbreit on Thursday March 27, 2014 @02:22AM (#7478914)
No, that's confusing, even to intermediate users. A dialog box is fine with the "Delete" action more pronounced. Another nice touch might be keeping around a "trash" that can be recovered from. No need to get too clever.
Re:Should "Yes, delete it" be red, or green? by mantrax3 on Thursday March 27, 2014 @01:35AM (#7478805)
Doesn't help if you click somewhere by accident and delete an email without noticing.
Re:Should "Yes, delete it" be red, or green? by MarkTee on Thursday March 27, 2014 @02:46AM (#7478964)
All you need to do is ensure that the undo option is highly visible (just like Gmail's; I've never caused irrevocable damage while using their web client).