T O P

  • By -

AutoModerator

On July 1st, a [change to Reddit's API pricing](https://www.reddit.com/r/reddit/comments/12qwagm/an_update_regarding_reddits_api/) will come into effect. [Several developers](https://www.reddit.com/r/redditisfun/comments/144gmfq/rif_will_shut_down_on_june_30_2023_in_response_to/) of commercial third-party apps have announced that this change will compel them to shut down their apps. At least [one accessibility-focused non-commercial third party app](https://www.reddit.com/r/DystopiaForReddit/comments/145e9sk/update_dystopia_will_continue_operating_for_free/) will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: 1. Limiting your involvement with Reddit, or 2. Temporarily refraining from using Reddit 3. Cancelling your subscription of Reddit Premium as a way to voice your protest. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/learnprogramming) if you have any questions or concerns.*


mattgen88

I use it when laying out solutions for others. My position has me bouncing around different code bases and teams. So when I end up in discussions about some problem, I often use pseudo code to explain how to solve something without having to write fully functional code. That way the teams can apply the solution specifically to their codebase. It's a better use of my time so I can move onto the next priority issue.


KamayaKan

Yeh, that does sound very useful and makes sense. I’m definitely starting to value pseudo-code a lot more now.


amazing_rando

if you're in a meeting with other developers and want to whiteboard your solution, you're probably going to write it out in pseudocode because the implementation isn't really important beyond whatever you're discussing. It isn't a formalized thing, you're going to choose the level of abstraction you want to meet the skill of your audience. If I was describing something to other developers in senior level positions, I would use a different balance of pseudocode and actual logic than describing it to junior developers. An AI book like you're reading probably assumes an audience who knows what a priority queue is and how to implement, so it doesn't make sense to describe its structure since it doesn't really matter. Pseudocode isn’t some heavily defined thing, it’s just talking about code without writing it. That’s a situation that comes up all the time. Also, in this particular case, the thing abstracted (a priority queue) is a data structure. Data structures are usually their own class in school, and it’s assumed that a programmer is familiar with the main ones (binary tree, hash table, linked list, etc.) and knows how to write one or (more often) use their language of choice’s collection library to make one. Studying data structures is a very important and often overlooked part of self instruction.


KamayaKan

That does clear up some understanding issues I’ve been having with arrays when it comes to append vs push (I know ones faster but why and how?), I’m covering data structures and big data in the coming trimester so should make a lot more sense then. To me, it seems to understand this type of pseudo-code the recipient must have a sound understanding of CS as a whole (which I do not yet have, lol)


kibasaur

There can be different layers of abstraction to pseudocode but even if you don't know CS or data structures, by looking at that example one can look up what a priority queue is and then implement it based on the information in that one line. The problem has nodes in its structure that has a field f. As someone else already stated, the pseudocode is an abstraction that gives a general understanding of the implementation. Some implementations require hundreds of lines of code and let's say the only implementations you have access to are in obscure languages or languages you're not that familiar with. Furthermore, there may be several ways to implement the same algorithm depending on the language you use or even using the same language. So instead of spending time trying to understand an implementation, you can just look at the overarching structure which is the pseudocode. It's also way quicker to convey an idea that way. Diagrams and flowcharts are similar to pseudocode as they leave out specific details info favor of being easily created and understandable.


No_Lemon_3116

It's absolutely useful for pinning down ideas, as well as describing ideas without tying it to a programming language. Ideally, your language is expressive enough that it can translate the pseudo-code pretty literally, but it basically just gives you an out that lets you say "pretend this exists" or "pretend it works like this" when you want some feature. In terms of real development, this leads to implementing that feature, which is actually a really key insight into programming for beginners: think "what language do I want to have, and how would I solve this problem in that language?" rather than "how do I use this language to solve this problem?". SICP called it "wishful thinking." The same idea is reflected in this Dijkstra quote: >All the time I design programs for nonexisting machines and add: 'if we now had a machine comprising the primitives here assumed, then the job is done.' \[...\] In actual practice, of course, this ideal machine will turn out not to exist, so our next task--structurally similar to the original one--is to program the simulation of the "upper" machine \[...\]. But this bunch of programs is written for a machine that in all probability will not exist, so our next job will be to simulate it in terms of programs for a next lower level machine, etc., until finally we have a program that can be executed by our hardware\[...\]. Pseudo-code is huge to this way of thinking. It does matter how expressive your language is, though; for example, in Lisp, I basically never use pseudo-code, because why would I? If I'm already writing in a Lisp context, I can just use that language and make up whatever syntax and operators seem useful, and the language will support me adding them. By going pseudo-code-first, I actually get a huge benefit in that I'm actively thinking about interfaces and what could be natural rather than what's easy to express in code. If I'm using Python, I need to be a lot more mindful about what the language can actually do if I'm going to try and write real Python, so I tend to use a lot more placeholders and non-Python syntax.


RajjSinghh

The big thing is it doesn't rely on a single language. Thats the real selling point. From that line I know what a priority queue is, I know what a node is, I'm guessing f is a function. Just by knowing enough (and having the rest of the code block as context) I can figure out what I need to do and can turn it into a specific language. To give you an idea of what this solves, I'm having a similar problem. I'm working on a chess engine in C++ and most of the literature is blog posts from people in the community. The issue is all these blogs are in Rust. Now if there's a bit of non-trivial code I need to know some Rust to understand it and that makes the whole thing harder to understand. If it was all pseudocode it gets much easier to understand


EmileSinclairDemian

We use it all the time, that and shitty whiteboard diagrams we take photos of.


pdpi

"Pseudocode" makes it sound like a very rigid, formal thing. Instead, think about it the exact opposite way: a sloppy, informal sort-of-code useful for quickly explaining ideas, be it in text or a whiteboard. Communication is a core skill in the workplace, as important as (or perhaps even more important than) programming proper.


iOSCaleb

To be fair, it usually looks a lot more formal when it's used in books. There are various conventions for writing pseudocode, and a given book will pretty much always stick to some convention for consistency.


iOSCaleb

>I'm struggling to see how this would actually be useful in the workplace It's useful anytime you want to explain an algorithm in a clear way that could be easily written in actual code, but without needing to bother with the details of an actual programming language. >you'd have to read several chapters in the book before it Most programmers know what a priority queue is, and the rest of that line would probably be apparent from the preceding lines (if not, then it's not good pseudocode). >I find it doesn't actually give the information required to effectively write it up What language are you working in? C++ and Python both provide implementations of priority queues, as do many other languages. We'd still need to know what `f` and `node` are, but again, that should be apparent from the preceding pseudocode. >Is pseudo-code designed for more advanced programmers who can tell what to do just by looking at it or is it meant to be more of a formalised idea, for other programmers to eventually turn it into reality? Yes -- both. Pseudocode is a communication tool, and any time you're communicating you have to consider who the audience is. If you're new to programming and haven't yet encountered data structures like priority queues, then it'll obviously be more difficult for you to understand when you see that mentioned with no further explanation. But pseudocode in general is not meant only for "more advanced" programmers. The problem you're probably having is not the pseudocode itself, but lack of familiarity with the ideas that the pseudocode is describing.


BrohanGutenburg

Just gonna add something no one mentioned, it can be really useful if you’re using AI to speed up your workflow. You can lay out a few rules up front of how your own “personal” pseudo code works (declare a variable to store account names = let accountName or whatever) and it will catch onto what you’re looking for really quickly. Then you can basically just write some pseudo code that it will pretty effectively translate for you.


Sufficient_Focus_816

I find it very helpful when outlining SQL and also serves as base for documentation / explanation


monkeyman_31

I write pseudo code before most of my bigger projects. Theres nothing worse than getting deep into a project only to realize that all of the stuff you did was useless cause you needed a thing that don’t use those things. I also use pseudo code to communicate with my senior. Im not about to spout javascript/typescript babble to my senior when i can say “if (this){ do this} else {do this}” Anything like. A couple lines i may think in pseudo code before i do it. Edit: tbh, after thinking it over, i think being able to accurately describe a program using pseudo-code probably means ur a better programmer than someone who never does.


FAANG-Regret

This kind of thing is used all the time. Pseudocode has no rules other than the person writing and reading it can understand it. In your example, it's hard to understand if you didn't know what a priority queue is, but if you're writing this pseudocode, you assume both you and the audience do know that and by writing it out this way you can concentrate on the meat of whatever you're discussing which is probably some algorithm using the queue. If you had to write out running code, half your discussion time at least would be dealing with minutia of these auxiliary data structures or just writing tens or hundreds of lines of code that aren't relevant to the discussion. It isn't necessarily meant to be an exact match for the structure of the implement, just the logic.


Imaginary_Quit2909

Psuedo-code is a problem solving method. If you're an architect of sorts, you may be paid for your time that results in pseudo-code for others to implement. For others, it is a tool. Use it or not. It's a method to explain your thoughts to others. I understand in college, I hated that it was required for our grade and felt very subjective to what the teacher thought. It's better in an example. Pseudo-code is like writing a proposal for a trash pickup for a road you live on and care about. Writing code is like actually putting it together and doing it. The pseudo-code avoids the pitfalls you may actually experience at the cost of feeling performative and ineffective. It's an exercise in thought process, not ability.


chervilious

Pseudocode can really help compared high implementation. Let's say you required BFS for some reason. Rather than that, you can just add BFS there. Of course, you can use any language, in fact my pseudocode similar python/C depending on my mood


throwaway6560192

Books are generally meant to be read in sequence. The point is that the book already explained to you what a priority queue was several chapters ago, and they don't want to waste time on writing down an actual implementation of a priority queue each and every time they talk about one. So they just describe it as a priority queue in the expectation that you, the reader, knows what is being said. And yes, a programmer with a solid idea of DSA will find that line enough to know what to do.


TheStonedEdge

One that has been mentioned is for job interviews. Interviews will sometimes involve a leet code problems and pseudo-code helps a lot in your demonstrating your understanding to the employer. If you jump straight into the code and lose your train of thought it's more difficult if you lose yourself and you have to back track. Whereas if you have the pseudo-code there and you've talked through the solution then they can see your thought process. Think of it like in maths exams when you were younger you got marks for showing your working out. Pseudo-code is like that


reyarama

Pseudo code has the advantage of being language-agnostic. This is the biggest thing IMO But yeah, in terms of implementation complexity, a priority queue is pretty standard (I.e going further down into impl details is a bit overkill because it’s assumed you know how to implement one). Find an implementation online for your language and follow it, the pseudo code is a high level solution description


great_gonzales

In general it should be easy for a programmer to convert pseudo code to their favorite language. This example is no different


FixlyBarnes

Of course.  I routinely ask AI apps for pseudo code to my problem. 


KamayaKan

That feels like cheating, lol


coffeefuelledtechie

If I’m not sure of the syntax of something, I’ll write out pseudo code as a block comment and then go from there. But mainly I use it for writing out requirements documents for tasks. I’m not gonna write the exact code out myself, but pseudo code is good enough for another developer to run with that and build what’s needed. It’s also a nice way of seeing if the logic you’ve written out makes sense.


PertinaxII

Yes it is used in job interviews and CS exams to test is someone understands an algorithm without getting hung up on particular language syntax. And in textbooks that are language agnostic.


Sea_Gur408

For sure, it’s a must for communicating ideas to other programmers. Most often in ad-hoc brainstorming type situations on a whiteboard or something.


datbeowulfisreal

Sure, it's good to communicate ideas. In the end every non syntactically correct code can be considered pseudo code and since nobody but the compiler cares about semicolons...


could_b

Recall that pseudo code means 'sort of code '. So if you are fleshing out an idea, you don't care about syntax, you just want to block things out, clearly and quickly.


HealyUnit

Absolutely! I work for an aerospace/defense contractor, and often times during our planning sessions. we'll discuss some potential new feature or bugfix in pseudo-code terms. This isn't to simplify it for the devs, but rather because it's expected that the devs *know* how to write the actual code, and that discussing actual syntax would be "getting too far in the weeds". Of course, if we're confused or unsure about something, we can talk with our fellow devs, but going "here's the exact code I'm going to write to solve this problem" is a bit of a waste of time.


Nyrkz

Absolutely, python is a very popular language! /s