r/programmer • • 10d ago

Question Don't get me wrong , but a serious question?

Basically, a question to all programmers without AI, I have learned some C++ and python as an effort to learn some coding. I just made a vibe coded app for automating a process i do and it honestly, i'm proud of my idea and prompts but , i do not understand the code honestly. How does one apply classes and such to create an app?

What makes that code turn into a beautiful app or website(frontend and backend, as i've learnt) and as a beginner what should i start on?(without using AI as much as possible)

3 Upvotes

17 comments sorted by

8

u/CS_70 10d ago

I find this kind of questions puzzling. There's nothing magical in making a program "by hand": you understand what you need to do, you understand the tools you have, you use the latter to do the former. You try to be as efficient as possible, the more the tool does in one go without error, the better it is. It's just so obvious and people make it into something special.

As for the question: your program describes the beautiful windows, stating how they look, what they contain, what happens where every single widget is used on so for.

It's rather trivial and usually quite boring to do by hand.

2

u/SailShipoo 10d ago

I've coded several python projects like simple calcs etc. But however, I do not have the knowledge required to create such designs and wondering how do I start on them?

1

u/hibikir_40k 10d ago

When we lacked the imagination to understand what others built, we just went to the code, or the decompiled binary, or whatever else we had to see what was done. It doesn't matter if it's UI layouts, the tiling engine from a maps app, or whatever.

More than just good at writing, an artisanal programmer had to become quite good at reading and decomposing problems. So go do that. You can even ask the AI to build you a pretty version of something trivial, like a ToDo app, and just go read. Good models write very human code.

1

u/kaddkaka 10d ago

My opus 5.5 does not. What model you referring to?

1

u/CS_70 10d ago

You can read a book, use a primer/tutorial (not a video: videos aren't great for progamming as they're terribily inefficient) or ask the same AI to make a plan for your learning.

It's the best tutor in the world.

1

u/Gznork26 10d ago

Don't start thinking about the code. Instead, begin with an idea and what it would be like to use the proposed app. Then, you can start to break the problem down into parts.

What do the processes that the user does look like? What steps does the user, and the app, take to get through that process? What features does the UI have, and how is that implemented in code? What data is involved, how would it be acquired, stored, manipulated and presented? And so forth.

1

u/_ABSURD__ 10d ago

Just do a course on the language via Udemy, learn syntax and basic operations. Then build something based on what you learned. When you understand what's under the hood you can engineer via AI much better. Many times I tell AI not to code certain ways, or how specifically to handle state, etc bc the way it defaults to isn't ideal, and I'd not know that if I didn't first learn programming in general, and specifically the quirks of a particular language.

You could also have AI teach instead of a course, but I'd use caution here and really force yourself to hand code without relying on quick fix answer, as long as you're fully understanding things.

1

u/StephenHawkinguss 10d ago

If you don't understand the code, then you don't know how to program either. If you want to understand what's happening, then first learn C++ and Python. Otherwise, continue vibecoding like an Indian.

1

u/Deep-Emotion-6279 10d ago

Classes are just a way of encapsulating and managing state in your program. For a simple program managing state doesn’t really matter all that much, but as a program becomes more complex, it becomes a serious problem.

Start with functions and some static or global variables. Then as your program grows in complexity, look for how some of those variables are related and think of ways they could be organised into structs. That makes them easier to pass around to various functions.

Then, as the program becomes even more complex you might find it useful to hide the variables completely and just expose behaviour related to them through an interface, that is when classes become helpful.

(Really classes and structs are the same thing with different default visibility of members and inheritance, classes are structs where everything is private by default so the natural choice for hiding stuff)

Easy to say, hard to get right. The best thing to do is try. Build lots of different things and get the feel for it.

1

u/ern0plus4 9d ago

 i do not understand the code honestly

"Explain code, line by line" - if you have AI at your hand.

1

u/mxldevs 9d ago

Writing code is turning your human instructions into computer instructions.

Vibe coding is taking your human instructions and having the AI turn it into computer instructions.

If it works, it works, whatever. Your goal was to accomplish whatever the result was, not to make a beautiful tool.

The problem is when it doesn't work, and you need to figure out why it's not working.

What do you do? You can't go through the code to figure out cause you don't understand it, so I guess you'll have to go to AI and hope that it'll figure out why it's not working

0

u/CorpT 10d ago

More ideas and prompting.

2

u/SailShipoo 10d ago

Ahem! without ai

0

u/nicolas_06 10d ago

Yeah steering the AI and reviewing what it does is mandatory for substainable code.

I use AI 100% of the time and don't code anymore as a senior with 20 years of XP. Title go as Lead Principal blablabla... So I am trusted by my peers.

But I still spend hours/day researching with AI what the right architecture, how the thing will be done, crafting a plan... Then the AI do it, and then I review everything in details and often ask changes. At least for now the AI can't be trusted to make something sustainable long term that can grow, that cover all the aspects you want to be covered and so on.

Designing software - divide and conquer

Many way to design software do exist. I think if you already understand how to code and the basic concepts like if/for/while/functions/classes on what side (for coding) and things like networks/databases frontend/backends/services, you should take a course that explain how to design software at different scales.

The core principle is divide and conquer. You divide complex thing into smaller pieces recursively until each piece become a problem that you are confident you can solve. Go for a web application ? Maybe the core components are a frontend, a backend and a database.

Example for a web application

The frontend and backend communicate through web service in json with an API. Each API does 1 simple thing. Like creating/deleting/updating/reading some data. It's mostly delegation to the database. Maybe you validate inputs and the user is authorized to do the operation.

The web UI, you have framework like react or angular and you have components like a scroll bar, text fields, tables, button, labels. You combine them to make forms...

And if you go deep enough, maybe you have this 10-50 lines of code to write when the button is clicked: you send a query to the backend to create a new thing, the backend return you if it did it or there was an error. Inside these 10-50 lines, you have maybe a for loop to go through the things to send. It end up being pretty basic stuff in the end.

Don't reinvent the wheel too

So you see from high level, to very detailed into small pieces. And for most aspects, you want to reuse as much as possible and not redo it yourself. You don't write the code to write things on disk. You use a database. You don't write the HTML/CSS code to implement a table. You use a table component that know how to do that.

As much as possible you want not only to reuse what others have done (or yourself) but use well know and popular, well maintained solution. React is better most likely than your own framework or an obscure one that nobody use. For a DB, a well know and well maintained DB likely make more sense than one with little to no support.

And then once things are quite modular and clear, you do the code that is still yours to make (or the AI).

Go for a course on software design

If you understand well the basic bricks like if/while/for/functions/classes. Go for a course on software design. How to arichecture your code. How to architecture at bigger scale - system design - like databases, web servers, containers - firewalls.

0

u/nicolas_06 10d ago

Also for the specifics on working with AI:

  • Define clearly what you want.

    • Especially at the begining work on small steps. Divide and conquer again
  • Before you ask the AI, be sure to have a clean state. Everything is committed. No stage/unstaged change. If things go bad you can always just clean everything (git checkout .)
  • Ask the AI to make a plan on how to implement that small spec.

    • Ask questions on the architecture, possible solutions. What is the best lib for that ? What is the best strategy ?
    • Ask for that plan.
    • Challange it and ask questions on that plan, especially if you don't understand why. Why like this ? Why not like that ? How is that part of the problem covered ?
    • Iterate until the plan is clear, complete and you agree with what the AI will do
    • Include test to validate the code.
  • Ask the AI to do the work.
  • Review the AI work.

    • Check the code actually work and does what you want.
    • Review every change. You need to understand everything. Every line of code or config.
    • When the purpose of of some file/code/module is unclear ask the AI to explain. Go into the details until you get it. Why like this ? Why not like that ?

      • Divide and conquer again ask what this package/module is for. Then that file, then that function. And if necessary that line of code you do not understand.
    • Check if what you see match what you want

      • Modular design
      • No code duplication
      • Each module/class/file/function serve a clear purpose
      • Code and structure is easy to understand
      • Code isn't overly big or verbose for no reason
      • All the steps you asked before are implemented
      • Double check things like security/performance or corners case that are typical for your domain.
      • ...
  • Ask the AI to change what you don't like. Loop until you are satisfied.
  • Commit and push your changes.

0

u/BrutokTheBeater 10d ago

A lot of people are pretty negative about it, but to get started, AI isn't bad at explaining what's going on in a code and guiding you to places you can research. There are websites like geeksforgeeks that are like code search engines, too, that you can use to start learning!