10 ms·
Uber open-sources tool to automatically clean up stale code
- tjalfi 6y agoPirahna, Uber's code cleanup tool, was previously discussed at https://news.ycombinator.com/item?id=23516823 https://news.ycombinator.com/item?id=23516823. The paper Pirahna: Reducing Feature Flag Debt at Uber is at https://github.com/uber/piranha/blob/master/report.pdf https://github.com/uber/piranha/blob/master/report.pdf.
- joering2 6y agoTotal nit pick, but I think Piranha is a totally wrong name here. Piranhas mostly feed on fresh meat, its known they are excited and eager to attack when victim moves in water, reassuring predator that its a healthy meat. Much better name would be Scavenger, or Vulture - a bird of prey that eats on dead meat. I assume you would rather cleanup your program from dead code, rather than strip it down to the bone from live functions :)
- alextheparrot 6y agoCould also change it to ¬Piranha
- detaro 6y agoAs far as I know that aspect of Piranhas is overhyped in popular culture, and they're pretty much omnivores, hunting fresh prey, scavenging on carcasses and eating plant matter. Agreed though that naming it after a pure scavenger would make more sense.
- Kaze404 6y agoWikipedia (and the sources listed) contradict this comment, saying Piranhas are vicious carnivores, with some even exhibiting cannibal behavior. https://pt.m.wikipedia.org/wiki/Piranha https://pt.m.wikipedia.org/wiki/Piranha
- judge2020 6y agoEnglish: https://en.wikipedia.org/wiki/Piranha https://en.wikipedia.org/wiki/Piranha > Although generally described as highly predatory and primarily feeding on fish, piranha diets vary extensively, leading to their classification as omnivorous. In addition to fish (occasionally even their own species), documented food items for piranhas include other vertebrates (mammals, birds, reptiles), invertebrates (insects, crustaceans), fruits, seeds, leaves and detritus. The diet often shifts with age and size. > In another study of more than 250 Serrasalmus rhombeus at Ji-Paraná (Machado) River, 75% to 81% (depending on season) of the stomach content was fish, but about 10% was fruits or seeds
- throeawayjoe 6y agoPiranhas are scavengers. The typical diet of red-bellied piranhas includes insects, worms, crustaceans, and fish.[13] In packs up to hundreds, piranhas have been known to feed on animals as large as egrets or capybara. Despite the piranha's reputation as a dangerous carnivore, it is actually primarily a scavenger and forager, and will mainly eat plants and insects during the rainy season when food is abundant. ~ Wikipedia.
- snthd 6y agohttps://en.wikipedia.org/wiki/Maggot_therapy https://en.wikipedia.org/wiki/Maggot_therapy might be a better analogy - you don't want to lose everything, just to clean out the necrotic bits.
- suff 6y agoOr maggot ?
- deleted 6y ago[deleted]
- laydn 6y agoI find it strange that a company which provides taxi hailing/routing technology felt the need to write a code cleanup tool.
- Swizec 6y agoWhen a company really loves growth and her VC daddy measures growth in headcount and all those talented engineers need something to do ...
- malux85 6y agoA company with billions in revenue, live updates routing around traffic, has complex machine learning modes predicting ride times and costs, and operates in something like 65 countries. Uber isn’t trivial
- zaphirplane 6y agoI didn’t know they did their own navigation, I assumed they would use one of the map services
- graeme 6y agoThose services charge corporate users. If uber develops nothing homegrown then it is subject to the whims of the major map services, mostly google. Most drivers use a 3rd party app in practice but uber probably needs to run mapping to avoid a source of weakness/cost. (Could be totally wrong about incentive structure)
- sverhagen 6y agoI thought between Google, VLS, Tom Tom, and I can't imagine that I just coughed up a complete list, there'd be enough competition to just procure this function competitively. I assumed it was more the Not Invented Here syndrome of a VC funded company who (until recently) had little of a cap on their Engineering spend.
- read_if_gay_ 6y ago
- erik_seaberg 6y agoI'm surprised to see that Boolean feature flags are common. We almost always ramp up percentages of UUID space or randomly chosen requests, to reduce the blast radius of a bad change.
- cdcarter 6y agoAt $JOB, we have feature flags of innumerable shapes and sizes. Some are based on account standing, some are % gradual rollout at random, others are a more thoughtful low-risk to high-risk rollout across customers and hosts. Some are manual flipped per customer/only on certain dev hosts. Literally anything you can think of, we have tied behavior to it. But, we've got good frameworks in place such that at the call sites where behavior diverges, it's just checking a boolean. if PermissionController.get().get(MyPerm.class): doA() else: doB(). I suspect this is pretty common, and its still easy to do the dead code elimination on.
- fennecfoxen 6y ago> if PermissionController.get().get(MyPerm.class): doA() else: doB(). oh, but if a behavior changes when a feature flag is active, there's a very strong case for it to be pluggable behavior strategy, so I like these so much better as an unconditional call to `self.getThingStrategy().execute()`
- anamexis 6y agoWon't `getThingStrategy()` do something like `if PermissionController.get().get(MyPerm.class): doA() else: doB()` ?
- rlayton2 6y agoYes, but you move the logic for deciding which branch to take to an underlying function. It pollutes the parent function less, but results in more overall functions for places to hide. Also, if the logic gets more complicated than just an if statement (if Permision... and date < cutoffdate: etc) you don't further pollute the parent function.
- W4ldi 6y agolol, I just thought about writing a script that does excactly that for javascript code. For easy implementation I thought about using annotations/comments that tell the script what to delete once a feature switch is being deleted.
- burtonator 6y agoWe just wrote one that does something similar for Typescript if anyone wants us to OSS it... The idea is that any stale code causes a HUGE amount of headache and removing it can be a life safer.
- stuckinaloop 6y agoI you were to OSS it I would definitely use it!
- southpolesteve 6y agoPlease do!
- Coxa 6y ago+1 !
- oars 6y agoWhat does OSS stand for? I know the OS stands for Open Source, but can't quite figure out how this would be used as a verb...
- jdxcode 6y agoit stands for "open-source software". It's never abbreviated as "OS" for obvious reasons.
- squillful 6y agoA similar tool, Vulture, exists for Python: https://github.com/jendrikseipp/vulture https://github.com/jendrikseipp/vulture I haven't used it yet myself, but discovered it during a search inspired by this post and thought it would be worth sharing. Definitely a trickier problem to solve for dynamic languages, but looks useful.
- creyes 6y agoIs this drastically different than https://unused.codes/ https://unused.codes/ ?
- dahfizz 6y agoFrom a quick reading, yes. Your tool identifies code that is never run. The featured tool identifies code that never _will be_ run if we make X change to the API.
- creyes 6y agooh interesting, tbanks for the clarification!
- mkr-plse 6y agoFor Piranha: a) Code related to stale flags is deleted b) Determination of staleness is based on status of the feature. c) Patch is created automatically and in a majority of the cases, compiles and passes tests. Based on my understanding of unused codes, a) unused codes is used to delete deadcode independent of features b) determining the deadcode is based on their usage in tests c) unclear whether the code is flagged for deletion or a patch created.
- therealdrag0 6y agoThe latest place I work has a dusty monolith full of skeletons and zombies. They’ve been migrating off it to micro services for like 5 years now. I’d be nice to have a tool to clean it up. But the use cases is slightly different than this one.
- mkr-plse 6y agoCan you elaborate further? It will be interesting to see other use cases for code cleanup.
- suff 6y agoWow, so if you wanted to leave an example of something, it would get auto-deleted? What could possibly go wrong?
- bartkappenburg 6y agoI like the concept using an analyzer like this but I've been looking for a tool that removes code that isn't perse stale but isn't executed for, say, x amount of time. We have quite a few online services in production of which I'm sure have a lot of code that isn't executed/touched by our users. As an example I'm thinking about code in if statements that are never reached because the statement always returns False. These tools discussed aren't capable of detecting such stale code. Any suggestions?
- mkr-plse 6y agoDo you already know the code that is not executed? If not, dynamic program analyses can help with identify the regions of code that are untouched (e.g., take a look at javaagent for Java programs). Subsequently, you can use some form of reachability analysis to determine which code blocks to delete without causing a compilation failure.
- stevefan1999 6y ago/jokes How does Pirahna clean itself?