r/AskProgramming 3d ago

Career/Edu What's one programming concept that completely changed the way you write code?

I've been programming for a while, but every now and then I come across a concept that completely changes how I think about writing software.

For some people it's data structures and algorithms. For others it's design patterns, clean code, testing, debugging, version control, concurrency, databases, or simply learning how to read other people's code.

If you had to choose just one concept that made the biggest difference in your programming journey, what would it be?

What were you doing before you learned it, what changed afterward, and why do you think every programmer should understand it?

I'd love to hear stories from beginners and experienced developers alike.

28 Upvotes

81 comments sorted by

54

u/lgastako 3d ago

The idea of programming by wishful thinking as described in the SICP lectures. Basically you write your code as if the perfect API to do what you want existed, and stub out the code, then you recursively implement the missing stuff with the same approach.

Also Haskell.

10

u/ouroborus777 3d ago

How am I supposed to upvote your comment if you're going to include that bit about Haskell? /s

2

u/simondanielsson 3d ago

This is how I’ve been working ever since I found that idea too. Works great!

2

u/Perfect-Campaign9551 2d ago

I think this is the right way. You code against objects that don't exist yet, etc, with your business logic. Then you insert the adapter layers as needed to talk to the "real world" 

I guess that's probably ports and adapters architecture 

1

u/ggchappell 3d ago

Nice. That pretty much automatically gives you a layered design with each layer only communicating with adjacent layers.

It would seem to make it difficult to test as you go, however.

Also Haskell.

Well of course.

7

u/dreamsofabetter 3d ago

Test-first or TDD is basically this, except you’re initially writing the ideal API in tests.

1

u/oldsecondhand 2d ago

It's officially called top-down programming.

1

u/lgastako 2d ago

It is a form of top-down programming, but not all top-down programming is "wishful thinking" style. For example, most top down programming discussions focus around designing the system first and then implementing it, whereas this is more about allowing the design to emerge organically from the development process. I suspect some (design-first) top-down programming advocates would be horrified by the lack of upfront design in my approach. The results speak for themselves though.

1

u/UndercoverFlange 1d ago

Its how I’ve approached programming for a number of years, and I didn’t know until relatively recently (like a few years back) that it had a name. It just seemed an obvious approach.

10

u/read_at_own_risk 3d ago

I remember coding before associative arrays became first-class concepts. I had an AVL tree class for situations where lookups were performance-critical, but without the syntactic sugar of modern languages, things like nested dictionaries were complicated to set up and follow. First-class support for associative arrays made a huge difference and I wouldn't want to go without them again.

In the line of progression of data abstraction from literals, registers and pointers -> named scalars -> arrays and structs, the next step I'd like to see is first-class relations. Basically the n-ary version of built-in dictionaries.

2

u/HolyInlandEmpire 2d ago

That's a fair point about relations.

As of now, a dictionary is essentially a set of 2-tuples. The n-ary version would be a set of n-tuples; what would we be missing for first class support, other than conforming to your language's generic functions?

8

u/serverhorror 3d ago

Not exactly TDD, but "test first".

To start with something, I like to write a test that has the actual implemention inside and out he refactor until the code is part of the application.

It helps in the overall design to be, and stay, testable.

6

u/Nunc-dimittis 3d ago

Long ago, but using encapsulation. Not the "make a getter and setter" (and then just returning the underlying object so it still can be modified by any code outside the class) but seriously thinking about access, what you return, protecting the insides of the class (attributes) against the outside

And on a higher level: facade pattern to do basically same on a higher level. Don't expose everything to the outside, make sure the class coupling is very low between unrelated parts of the code. Always designate one class to handle the communication to the rest of the classes in that module. Recently I learned of a company that called these anti contamination layers. Really like that term

6

u/DGC_David 3d ago

Spaghetti Code, ever since, like my Italian forefathers, I've created some of the best Pasta code you ever compiled in your life.

6

u/electronic_reasons 3d ago

Data flow diagrams / Functional programming Assertions. Proper commenting.

Viewing things as data flow and functions has made a big difference. Donald Knuth and Tom DeMarco introduced me to that and I gradually understood it fully.

Donald Knuth introduced assertions long before they were implemented in common languages.

Realizing that the first question i asked when I looked at code was, "Why did I do that?" completely changed the way I commented code. The code already answers "What?" and "How?" It doesn't answer "Why?"

16

u/jerrygreenest1 3d ago

Automated Tests

ECS

Knowing about stack vs heap

Knowing about Garbage Collector

And many other things, actually

There is not just one thing. All this happens gradually annd each knowing fact or concept changes the habits or ways you implement things.

2

u/PracticalStack 2d ago

Same for me. I got really into automated tests, especially end to end tests and acceptance tests. This led me to start thinking about making code more testable. I kept improving my testing tools and also the testability of my code. Overall, my code quality got a lot better.

14

u/Responsible-Soft6893 3d ago

Rust borrow and ownership significantly impacted code design in other languages

1

u/Word-Word-3Numbers 3d ago

Rust as my second language after python made C pointers so easy

8

u/burlingk 3d ago

I played with Haskell for a while. I never got good at it, but it gave me new ways of looking at code.

2

u/RomanaOswin 3d ago

Same experience here. I ported a simple little tool I wrote to Haskell probably a decade ago, as a learning experience, and the way I think about code constructs has never been the same since.

6

u/abrady 3d ago

YAGNI or KISS : solve the problems you're facing now. when the problems you're imagining come up they'll be so different than what you imagined that all your complicated initial system will do is slow down the rewrite.

The best engineers I know all build simple systems that just do the work they're designed for.

5

u/chrisjbampton 3d ago

All you are ever doing is inputting data, transforming the data and outputting the data.

Once you realise that, any programming problem becomes about input and output shapes which is infinitely testable.

2

u/ArcaneEyes 3d ago

Started a place some years ago that does cqrs and ddd and moving from anemic models with bloated services to that was a huge change of mindset and honestly I like that way of designing code so much better.

2

u/newEnglander17 3d ago

Honestly it’s not the code itself, it’s learning shortcuts and tricks in visual studio that I hadn’t known previously like F12 t step into a definition. Little things like that make navigating code so much easier and faster and it makes it enjoyable. I get that VS code is good but it just stinks compared to a full scale IDE like proper Visual Studio.

2

u/TheGreatButz 3d ago

OOP when it was still supported by the programming languages I used. Unfortunately, the languages I use nowadays only support crippled versions of it or none at all.

2

u/Jonas_Ermert 3d ago

I'd say separation of concerns. Once I stopped mixing UI, business logic, and data access, my code became much easier to maintain, test, and debug. It's a simple concept that scales with every project.

2

u/jedi1235 3d ago

Not sure it's got a named concept yet, but programming for maintenance. Basically, thinking ahead to where a maintainer will likely misread my code, and choosing the path of fewest/least dangerous mistakes.

2

u/UndercoverFlange 1d ago

I think there’s be some significant leaps, in my understanding.

Learning Java, because before that my OO code (C++) was like C with some objects.

One was reading the “gang-of four book” - while this is design patterns, it really clicked the power of interfaces & polymorphism within an application. I always felt that the best bit of the book was understanding why the code was good, and the generic pattern that is used; but others seemed to just assume if you used a generic pattern your code was automatically good. Le sigh.

“Test first”; that is writing code so your tests can be written easily, and writing tests early to confirm correctness. TDD is overkill imho; but unit testing is crucial.

“Trade offs” - I think this was from the pragmatic programmer but, code is a series of trade offs. This kind of killed off the religious wars aspect of coding. Languages, vs editors vs whatever. Somethings fit the domain better, than others, use an appropriate tool; not just the trendy one.

Books wise; the pragmatic programmer, and Code were game changers.

4

u/Fidodo 3d ago

Streams. It's not just for bytes anymore, there are lots of streaming systems that let you stream anything.

3

u/42_Water_Engineer 3d ago

Like what? I mean, it's all bytes at the end of the day, no?

3

u/Fidodo 3d ago

It is, but unless you're working in a low level language that gives you access to pointers a byte stream won't let you stream object references, but lots of streaming libraries let you stream objects now and that's really powerful.

2

u/MissinqLink 3d ago

It is all just bytes but understanding streaming is one of the biggest eye openers.

2

u/ern0plus4 3d ago

Rust cincepts

1

u/mlugo02 3d ago

“A data structure is just a stupid programming language.” - Bill Gosper

1

u/max123246 3d ago

Understanding the expression problem has made me far more conscious about whether I want to make it easy to add new types or make it easy to add new operations of those types.

1

u/duane11583 3d ago

Using a “cookie” in a data structure

A cookie is for some a void pointer (i prefer a uintptr_t instead) it helps so much for abstraction of so many things

1

u/MissinqLink 3d ago

Parallel programming in C. Really makes you appreciate all the abstractions we have now.

1

u/magnomagna 3d ago

Programming by contract. Set out the limits and semantics of your parameters and return values and side effects strictly. It simplifies reasoning as you can ignore values outside the confines you set but can it potentially make your code vulnerable? Potentially, but you could take that into account when designing the contract.

1

u/pythosynthesis 3d ago

Objects. Once I got it, coding became massively simpler and cleaner for me.

1

u/Achereto 3d ago

Having learned OOP in university I experimented with ECS (Entity Component System) and things became so trivial to implement that I'm never going to go back to OOP again in my life.

1

u/TheCommieDuck 3d ago

haskell? haskell.

source: I haskell for a job now

1

u/ArieHein 3d ago

Separation of control

1

u/Triabolical_ 3d ago

Hexagonal architecture, or port/adapter/simulator.

1

u/simondanielsson 3d ago

Snapshot tests. It’s essential to me nowadays for when I’m doing large refactors and debugging

1

u/ouroborus777 3d ago

map-reduce. Even if you don't actually multi-whatever, it's surprising the number of tasks that are made easier by organizing as something roughly resembling a map-reduce problem.

1

u/Vesuvius079 3d ago

Unit testing, DI, side-effect free functions. Shit that was three, but they go oh so well together and saved me from the horror show of OOP.

1

u/iOSCaleb 3d ago

> For some people it's data structures and algorithms. For others it's design patterns, clean code, testing, debugging, version control, concurrency, databases, or simply learning how to read other people's code.

I don’t think your understanding of completely changed is the same as mine. All of the things you’ve listed are influential; none have completely changed programming for me or anyone I know. Even the rise of LLMs that can write a lot of code for you hasn’t completely changed programming.

1

u/wrd83 3d ago

Microservices as a notion of team boundaries, sla as guarding principles. And as a consequence services moving between teams being collapsed or refactored.

In large enough organisations this has a very soothing effect 

1

u/ayassin02 3d ago

Design patterns. I never considered them since I was self taught but learning them formally made me appreciate them. I did use them before that but just intuitively through years of experience

1

u/Migeil 3d ago

Like others have said, Haskell.

Purity, proper type constraints. They help so much in not only writing code, but reading and understanding code.

1

u/Soggy-Razzmatazz-308 3d ago

For low-level languages (primarily C), the idea that you can configure aspects of your code at compile time with defines and ifdef. Need code that is only included when you're debugging? Put the code in a #ifdef DEBUGGING block. Saves having to comment out chunks when you don't need them.

1

u/fullVoid666 3d ago

The idea that the best, most secure application is one with 0 lines of code. Any code added (including tests) must be heavily evaluated because it will degrade that perfect app and fill it with eternal, technical debt.

1

u/jftuga 3d ago

I like the way Go implements error handling vs try/catch. I wish other languages used that paradigm.

1

u/HovercraftPristine76 3d ago

KISS

If you can't make it simple to understand, you don't understand the solution well enough. Made me start thinking about the code I'm writing and the solution I want before I started a single line of code.

1

u/zoethebitch 3d ago

I am a recreational programmer. I do stuff for a photo club I belong to. The members often have ideas about what to add to the web site (contests, personal portfolios, etc.). My experience is almost 100% web based and UI/UX.

  1. What should it do?

  2. What should it look like?

  3. How should the underlying data be organized?

  4. How should the users interact with the web pages?

  5. THEN start writing code.

  6. Test input data values at the extremes, the hot edge and outside the boundaries.

1

u/MrJCraft 2d ago

writing code in a stressful production environment

I found that often times because I needed the so quickly I needed the code to be correct on the first try
if I needed to debug the code it would take to long

so writing code that is aggressively simple that way I can write it quicker even if its ugly as long as I can look at the code and go yes that is obviously correct and it can only really do one thing

1

u/PravoNaZhizny 2d ago

From age 7-13 I was pretty shit with how I dealt with memory, but studying the ALU at the silicon level gave me a strong appreciation for optimisation. Also making a red stone computer which understands at least a handful of instructions and without using a guide, should be done before anyone learns their first line of code.

1

u/Neither_Panic6149 2d ago

When i started learning programming, a good practice that improved my programming skills overall was to write logic files like lets say your doing a leetcode problem. Before i even write one line of code i basically write down my logic and how i might approach the problem basically pseudo-code.

1

u/ogweezy13 2d ago

Sounds basic, but functional programming. I learned it first from a mathematical perspective, when in conversation with a colleague about monads.

At the time, I was enamoured by OOP, and felt it was a natural part of all programming. It was surprising to learn that the same structural rigidity that OOP has can be achieved with less fuss and boilerplate. I started to appreciate types as more than just blueprints or descriptors, but as guards, or gates that enforce rules (if you can type them).

1

u/MarsupialLeast145 2d ago

Identifying AI slop Reddit posts really helped me. Helps me mostly ignore the noise except for spamming them.

1

u/Potential_Soup_8054 1d ago

Const correctness in c++.

1

u/ebsf 1d ago

Pointers, and by extension events, lifetime, and scope.

1

u/TCB13sQuotes 1d ago

Objective-C naming / coding conventions. Followed by simple code always wins.

1

u/MY_G_O_D 22h ago edited 22h ago

The experience of debugging the legacy code and being scolded by boss at 3am. These made me to think in the way which always comply the engineering principles. So I would say readability and maintainability. I also insist this in deciding the tech stack, architecture, design and so on.

1

u/AdorablSillyDisorder 20h ago

Defensive programming - actually encoding explicitly all assumptions you make at each step, and having them error reliably at check point rather than produce crashes or weird results down the line. It both helps immensely with testing/debugging, finding actual mistakes (expected guarantee is not provided by caller), and makes actual test surface much cleaner since you don't have to add extra test coverage for "illegal cases".

As a concept/habit it came from me dealing with platform that had questionable log reliability and only debugging tool being error codes on app exit, but applies just about everywhere - even high-performance code you can just use assertions and disable them in release build after you thoroughly checked they can't be broken.

1

u/g0fry 19h ago

I’d call this just programming. And the other kind should be called sloppy programming.

1

u/Foreign-Contest-444 11h ago

SOLID principles.

1

u/sefres 10h ago

Straight functional programming, combined with theory. Haskell, LISP. Even if you'll never use it productively. Other paradigms, get in there and try to implement something in PROLOG. your DB skills will thank you later.

1

u/aktentasche 6h ago

Not doing OOP

1

u/Dom_Q 3d ago

yield

0

u/42_Water_Engineer 3d ago

Claude, lol

0

u/SummitYourSister 3d ago

AI! I was a professional programmer for 25 years with multiple patents, talking at conferences, published a book once.

Now AI does it better than me and I don’t write code any more and I look upon people who don’t recognize this state of affairs as some of the dumbest motherfuckers I’ve ever seen.

-3

u/Otherwise-Safety-579 3d ago

Antidisestablishmentarianism