Menu

Post image 1
Post image 2
1 / 2
0

Finding Structurally Duplicate Go Functions with AST Hashing

DEV Community·alexey.zh·29 days ago
#SrL0rbUY
#why#it#extract#fullscreen#exit#enter
Reading 0:00
15s threshold

Copy-paste is one of those engineering problems that starts harmless. You copy one handler. You rename User to Order . You change a few string literals. You adjust one validation branch. Everything works. Then six months later, the same bug is fixed in one copy but not the other. That is the kind of duplication godedup is built to find. godedup is a small Go CLI tool that finds structurally duplicate functions in Go code. It does not compare raw text. It does not care if variable names changed. It does not care if string literals changed. It looks at the shape of the code. In other words, it tries to answer a practical question: “Did I copy this function and slightly edit it?” The problem with text-based duplication checks A simple duplicate detector can compare lines of code. That works when two functions are literally identical. But real copy-paste rarely stays identical. It usually becomes this: func validateUser ( userName string ) error { if userName == "" { return errors .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More