5 ms·
the "useCanUseTool.tsx" hook, is definitely something I would hate seeing in any code base I come across. It's extremely nested, it's basically an if statement
by Insensitivity 6mo ago
the "useCanUseTool.tsx" hook, is definitely something I would hate seeing in any code base I come across.
It's extremely nested, it's basically an if statement soup
`useTypeahead.tsx` is even worse, extremely nested, a ton of "if else" statements, I doubt you'd look at it and think this is sane code
- luc_ 6mo agoFits with the origin story of Claude Code...
- werdnapk 6mo agoinsert "AI is just if statements" meme
- loevborg 6mo agouseCanUseTool.tsx looks special, maybe it'scodegen'ed or copy 'n pasted? `_c` as an import name, no comments, use of promises instead of async function. Or maybe it's just bad vibing...
- Insensitivity 6mo agoMaybe, I do suspect _some_ parts are codegen or source map artifacts. But if you take a look at the other file, for example `useTypeahead` you'd see, even if there are a few code-gen / source-map artifacts, you still see the core logic, and behavior, is just a big bowl of soup
- Overpower0416 6mo agoexport function extractSearchToken(completionToken: { token: string; isQuoted?: boolean; }): string { if (completionToken.isQuoted) { // Remove @" prefix and optional closing " return completionToken.token.slice(2).replace(/"$/, ''); } else if (completionToken.token.startsWith('@')) { return completionToken.token.substring(1); } else { return completionToken.token; } } Why even use else if with return...
- worksonmine 6mo ago> Why even use else if with return... What is the problem with that? How would you write that snippet? It is common in the new functional js landscape, even if it is pass-by-ref.
- Overpower0416 6mo agoUsing guard clauses. Way more readable and easy to work with. export function extractSearchToken(completionToken: { token: string; isQuoted?: boolean; }): string { if (completionToken.isQuoted) { return completionToken.token.slice(2).replace(/"$/, ''); } if (completionToken.token.startsWith('@')) { return completionToken.token.substring(1); } return completionToken.token; }
- kelnos 6mo agoI always write code like that. I don't like early returns. This approximates `if` statements being an expression that returns something.
- catlifeonmars 6mo agoI’m not strongly opinionated, especially with such a short function, but in general early return makes it so you don’t need to keep the whole function body in your head to understand the logic. Often it saves you having to read the whole function body too. But you can achieve a similar effect by keeping your functions small, in which case I think both styles are roughly equivalent.
- whilenot-dev 6mo ago> This approximates `if` statements being an expression that returns something. Do you care to elaborate? "if (...) return ...;" looks closer to an expression for me: export function extractSearchToken(completionToken: { token: string; isQuoted?: boolean }): string { if (completionToken.isQuoted) return completionToken.token.slice(2).replace(/"$/, ''); if (completionToken.token.startsWith('@')) return completionToken.token.substring(1); return completionToken.token; }
- matltc 6mo agoLol even the name is crazy
- duckmysick 6mo agoI'm not that familiar with TypeScript/JavaScript - what would be a proper way of handling complex logic? Switch statements? Decision tables?
- deleted 6mo ago[deleted]
- catlifeonmars 6mo agoHere I think the logic is unnecessarily complex. isQuoted is doing work that is implicit in the token.