8 ms·
Ask HN: Does anyone use pseudocode in the real world?
Got into a chat with a friend (doing a CS degree) about pseudocode. I've always considered pseudocode useless, and I've never used it in practice. Just curious what other folks' experience is like.
- detaro 3y agofor the same things as in academia (sketching algorithms), but that just doesn't come up very often for most people
- navjack27 3y agoI mean, I sketch ideas out in Excel formulas or quick little Python scripts that I talk out with GitHub co-pilot...
- bjourne 3y agoIt's often used in scientific publishing where it is preferred over executable code.
- kojeovo 3y agomostly when working with strongly typed languages (go, typescript) and i dont want to go through the trouble of writing out perfect syntax to share a quick idea. ends up kinda looking like python i suppose
- dvt 3y agoAll the time. I usually write a block comment explaining what I'm trying to do with a piece of code (method/class/etc.) before I even write any "real" code. The pseudocode varies between full English sentences ("1. Make sure the folder exists before creating file, 2. Create file with sanitized name, etc.") to more schematic ("sanitize file name AND create file IFF folder exists"). To me, it's comparable to writing a paper; I could never write a paper without a proper outline and knowing where I'm starting and where I'm going.
- SomeHacker44 3y agoExactly this! Virtually all my code is first written in plain language pseudo code in comments before being written. Even in languages I am fluent in. This way anyone can understand what my code is doing when reading it too.
- Rochus 3y agoNot a single time in my 35 years as a software engineer; in times I use state or other diagrams, but besides that I just explain the intention in prose comments where necessary. Pseudocode is just another "language" you have to learn, which is why I prefer algorithm or compiler books with examples in common programming languages.
- max_ 3y agoIts great for writing code-agnostic specifications for software. And is often easier to read than actual code. Languages like TLA+ can be considered as a form of pseudocode as they cannot be compiled down to code. Yet TLA+ is used very much in the real world for describing complex algorithms.
- weare138 3y agoI've always wondered why we haven't just come up with an actual language with a pseudocode syntax. Even if the focus was on prototyping with the intention of transpiling to a different lang later it seems like it would save us some time having proper dev tools for prototyping with pseudocode.
- hwayne 3y agoALGOL was supposed to be this, but then people kept on making extensions to make it compilable.
- jaredsohn 3y agoI think a part of the purpose of pseudocode is it helps you focus on what the code is trying to do and it removes the distractions of syntax, style, etc. You can probably just use LLMs to convert the pseudocode anyway.
- isbvhodnvemrwvn 3y agoOften in code reviews and other discussions to describe some alternative approaches.
- hwayne 3y agoIt comes in handy sometimes. It's most useful when you know what algorithm you want to implement, but have to do it in a language you don't know too well. Like if I have to do something in Rust or JavaScript.
- jgamman 3y agoyes - i'm not a programmer but i need to translate business rules for my contractors to build. it helps us 'meet in the middle' when discussing abstract things.
- yen223 3y agoI did quite recently, to communicate requirements to devs working in a language I wasn't familiar with.
- Graffur 3y agoIf I am whiteboarding with people in work I definitely don't try do proper syntax etc. That is pseudocode to me.
- sircastor 3y agoYes. When you’re having a conversation about programming concepts, but you don’t want to get lost in details of implementation or gotchas related to a given language, you operate in pseudocode. I will note though that when I was in school there was an “official” pseudo code, and I’ve never met anyone who uses that. It’s usually just a lazy C syntax.
- nivertech 3y agoYes. - In design docs: - use pseudocode for complex business logic, and/or algorithmic parts (similarly as it's used in scientific papers) - Also use it when MSD (Message Sequence Diagrams) would be too complex, or too detailed - Pro tip: If you're writing design documents and you're pressed for time, start by writing pseudocode. Later, if you have extra time, you can convert the simpler ones into diagrams or other relevant visuals. - In code comments: - use it in case when code is non-trivial, or hard to understand - use it for a placeholder for yet to be written code, or in TODOs
- schwartzworld 3y agoI do it a lot in code review. If I'm asking for a change, I like to offer a suggestion of how i'd implement it, but I'm not actually going to write all the code and get it running, pseudocode is enough. Then there's always the joke about Ruby, where you just write pseudocode and the interpreter just runs it.
- jones1618 3y agoDefinitely. How could you not? Even w/ auto-complete/CoPilot coding is never as fast as thought, especially when mapping out broad outlines of an implementation. Besides, test-first development is inherently writing pseudocode where you write MagicFunction() and then TestMagicFunction() and iterate to flesh out both. Also, who doesn't write a first pass of some code and then drops a comment that says /* handle special cases x, y and z here */ for later? All of that is pseudocode.
- hinata08 3y agoYes Understanding the algorithm, the states, the model, the constraints, the dependencies, the properties,... at all times is what makes you an engineer. Technical standards and publications about real life issues (like mutex, db management,...) often use pseudo code, because the actual implementation doesn't matter. Pseudo code is also relevant because languages change anyway. And in some companies and industries, several teams use totally different codes you won't know of. Coding right away is possible. But it's not the same job. You can be paid big for actually thinking through your code, and not just writing it.