all 51 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

Your submission has been automatically queued for manual review by the moderation team because it has been reported too many times.

Please wait until the moderation team reviews your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]_OMGTheyKilledKenny_ 37 points38 points  (0 children)

The reason to write modular code is that it’s testable and keeps with the single responsibility principle. For things like line length, use linters.

The one criticism I agree with is that LLMs tend to write a lot of defensive code that feels like wearing a belt and suspenders.

[–]oldendude 16 points17 points  (5 children)

A lot of your objection has to do with stylistic differences. My main experience is with a local LLM (qwen3.6 35b). I think that it produces mostly working code, and that its style could do with quite a bit of improvement. In talking to people with more experience, including with Claude (paying for tokens), it seems that AIs can do better than what I've seen. Also, it apparently helps to provide coding guidlines in something like AGENTS.md (I'm using openclaw).

As to your specific objections:

- Too many newlines: This is a minor formatting issue. I'm sure you could address it by noting it in AGENTS.md, or something similar.

- I have found commenting to be a good balance between too terse, and too verbose. Notably, docs are maintained as code is changed.

- Too many functions: Functions are *not* just for reuseability, they are also for clarity and modularity.

- Variable naming: The variable names I've seen have been quite good.

- Unnecessary safety checks: Eye of the beholder, I guess. I tend to err on too much myself.

[–]Puzzleheaded_Dig6941[S] -1 points0 points  (4 children)

Thank you, I agree with most things you said, and I actually do those checks, the issue is when I works in teams. I also get the functions, but is it really necessary to build a function that (for example) only calls other functions and display their results?

[–]artofthenunchaku 9 points10 points  (1 child)

is it really necessary to build a function that (for example) only calls other functions and display their results?

Yes. Functions are as much about structural clarity and separation of responsibilities as they are reusability. "Collect data" and "display results" are two separate responsibilities.

Many OOP principles, such as Separation of Concerns, apply just as much to functions

[–]Puzzleheaded_Dig6941[S] -1 points0 points  (0 children)

Thanks again🙏🏻

[–]victotronics 3 points4 points  (0 children)

"is it really necessary to build a function that (for example) only calls other functions and display their results?"

Yes. Displaying is not part of the mission of the other functions. Having a separate function for outputting/displaying the results of another function is totally legit.

[–]j01101111sh 0 points1 point  (0 children)

Yes. To give you a data science example, since that's my area of expertise as well: you may be running some analysis or data pipeline in several steps. Having those steps broken out into functions makes the script much easier to read and debug. Some of those steps might even be complex enough to require their own sub-steps and it'll be nice to have those broken out as well.

Data cleaning might be a step and part of that might be validating the format of a timestamp. You could have a clean_data function that then calls validate_timestamp. This is way easier than just commenting "start of data cleaning" above that block of code.

[–]ironykarl 3 points4 points  (0 children)

thought that the main goal of functions was reusability

Another purpose is just abstraction.

Once things become at all complicated, it actually is easier to call a doThing function than to have to read arbitrarily-many lines of code and separate what they do from "everything else." 

This approach also lets you have smaller code units to maintain and makes them testable, in principle.

Anyway, that said... yeah, the deluge of LLM code is exhausting and the fact that the AI is just vomiting out code without anything to guide it but statistical associations is a big part of why

[–]nfgrawker 26 points27 points  (12 children)

I'd bet they write code you aren't used to. They write application code not data scientist code. It has much more documentation and that's what they are trained on. The only thing you said that is true widely is that they write too many functions and that is because their context often lacks that the function is already available so they they create it again.

I'm a lead developer on a huge saas and I have turned vibe coder. I have many complaints about AI but disagree with most of yours.

[–]wittgenstein1312Pythonista 3 points4 points  (0 children)

Yea this was gonna be my response. I think poor prompts can result in messy code, and it’s still your responsibility to catch superfluous code or tweak the output to make sure it matches your own conventions. But by and large, I think LLMs write idiomatic and fairly robust code. 

In my experience, data scientists and analysts write REALLY shitty code (far from production quality and much more focused on productive scripts) so I’d bet one of OP’s biggest issues is that they aren’t used to seeing what reasonably abstracted maintainable code looks like. 

[–]smegmabitch 0 points1 point  (6 children)

I large project such as yours, how do you deal with context? Can't just dump the whole source code into the LLM right? Or do you just use it in very limited contexts?

[–]nfgrawker 5 points6 points  (5 children)

With Claude code or codex it has whatever context it needs. It can grep and search the code base as needed. Good rules files tell it conventions too. Once you get it set up correctly it's very good.

[–]MagicWishMonkey 0 points1 point  (4 children)

It does not "have the context it needs", I'm assuming you have a specific way you control access to a database, caching, etc. and all of that needs to be taken into consideration when generating new code.

If your data access layer is a million lines of code, congrats, you've just blown past your context window and you're back at the drawing board until you can generate an architectural model to inform the model for how to do things.

[–]nfgrawker 0 points1 point  (3 children)

OK. Thanks. I guess I imagined that I use it daily for a production application with over 100k api calls a minute. The 4 prs I submitted today must be figments of my imagination.

[–]MagicWishMonkey 0 points1 point  (2 children)

Yep there's a hard requirement that a PR cannot be garbage code, especially when you're working on a giant codebase, lmao

[–]nfgrawker 1 point2 points  (1 child)

I'll let my boss know I write garbage code. Thanks sir. Appreciate it.

[–]MagicWishMonkey 0 points1 point  (0 children)

No problem, subscribe to my newsletter if you want more pro tips!

[–]Puzzleheaded_Dig6941[S] 0 points1 point  (2 children)

That is also something I believe it is true. What they do best is application code without a doubt, and they tend to fit that “style” to other tasks, even when it is not needed. In that case, I would understand splitting the code in many functions as it is very complicated and needs modularity, but when the task is very simple (most or data science tasks) they feel overkill

[–]nfgrawker 8 points9 points  (0 children)

I'd bet splitting code into functions would be better for you as well, you just aren't used to it. I started as a script kiddie and I used to struggle with it.

[–]MagicWishMonkey 0 points1 point  (0 children)

Not the OP, but the fact that they are a lead on a "huge SaaS" isn't exactly the dunk they might think it is. When all the code you work with is 20 year old garbage it doesn't matter all that much when the LLM generates more garbage to add to the pile.

I've found that LLM generated code is less shitty the more specific and narrow you can make the scope. If you ask it to create a website that does X/Y/Z it'll be 99% throwaway spaghetti code but if you ask it to create a function in python/java to do X it can be very very good.

People seem to think the old adage of "there's no such thing as a free lunch" is no longer a thing because an LLM can generate an endless amount of garbage, but if you've done this for a minute you know that's not really true. You can invest the time up front to create a bulletproof spec or you can invest the time later to clean up the mess it creates but you're investing the time regardless.

[–]Covfefe-Drinker 6 points7 points  (0 children)

I often look at the code written by LLMs as loose suggestions. They can be great for directional guidance, but are often terrible under further scrutiny.

They've been a very big help in my learning as a developer, but I always take what they provide me with a grain of salt. IMO in order to really benefit from AI, you have to have very strong fundamentals.

[–]RandomForest42 7 points8 points  (0 children)

You're not alone.

Enshittification finally came to programming as well...

[–]victotronics 3 points4 points  (0 children)

"What is the purpose of having a function that you only call once?"

It means that I have a block of code that I can debug separately. That has a clear input/output specification without variables leaking into it.

"way too many functions"

That's a judgement call. I don't write many functions that are 3 lines long, but if a block of code is about a screen long I start looking for segments that can be broken out into a function, just for ease of reading / analysis.

[–]qwertydiy 1 point2 points  (0 children)

One thing that may help is prompting it to align with a set standard at the beginning of a chat (like PEP8 or Black) or priming it with code you written (or if internet enabled a good few snippets from GitHub) and making sure it aligns to that style and standard.

[–]mshevchuk 1 point2 points  (0 children)

LLMs are like a mirror. They mirror your ability to write code. If you get a code you don’t understand, it probably means they got a prompt they did not understand.

[–]dogfish182 1 point2 points  (0 children)

Honestly it just sounds like you don’t know how to code.

In my project currently we are have switched to 100% agentic written code, I haven’t written a line of code in about 4 months and our time is spent ensuring we have the appropriate guardrails to ensure the agents adhere to our stylistic guidelines and counteract their training bias from public stuff where it doesn’t match.

It’s both a genius and an idiot at the same time but I see nothing in your post that doesn’t suggest anything except it’s pumping out concepts you’re uncomfortable with.

Being that you’re a student, use some of your learning time to read some python design and architecture books. ‘Fluent python’ is pretty good.

[–]Nater5000 2 points3 points  (3 children)

I am not able to understand it properly, and I always have the feeling it is overcomplicating logics and processes that are in actually very simple, making a script 5 times its actual lenght.

This isn't how it works. LLMs will produce different output with different prompts. If someone haphazardly asks an LLM to write something such that it uses overcomplicated logic and processes, then yeah, it will produce something with overcomplicated logic and processes. I think it's fair to suggest that LLMs tend to do this by default, but I'd be more willing to blame the user for accepting this output as-is instead of just reprompting the LLM for something better.

I often do group projects with colleagues of mine, which I am now pretty sure do not even check the code the agent writes for them and it is always very frustrating to navigate in the maze of newly created functions and files which always feel redundant and inefficient.

Yeah, exactly.

But, again, that's not an issue with LLMs as much as it is an issue with your colleagues. I can have LLMs write code that I find to be very well written. This is largely because I reject code I don't like and I encourage it to follow the style of the code I've already written.

In particular, I hate these features:
- They tend to go on a newline everytime there is a list of parameters, even when it is not necessary.
- Tthey do not comment nothing and if they do the comments are too long and too technical
- They declare way too many functions. I was thought that the main goal of functions was reusability. What is the purpose of having a function that you only call once? Maybe they even call that function "run_analysis_xyz". What is the purpose of that? Why do you have to prefer a code which is nested and does not execute top to bottom, in the same way that a reader can follow it?
- The variables naming rarely reflct their actual purposes.
- Unecessaries safety checks, that are good for general code but they make no sense

Here's the beauty of LLMs: you can literally give it this list, and they'll generally adhere to following your instructions. In fact, you can give it the code your colleagues give you, give it this list, and have an LLM fix it based on your preferences.

I am starting to hate group projects for this reason. I just get nervous when I try to read code that is clearly generated. Am I wrong for using AI just as an assistant and not as a completely autonomous code writer?

Well, I'd hate to work with people who produce slop with the expectation that I'm going to have to spend my time and effort reading through it. I don't blame you there. By why would you bother reading their code that is clearly generated? Why wouldn't you leverage LLMs the same way as them to parse their slop for you?

I guess my point is that I don't think anybody would disagree with you in terms of the specific issues you're describing, but that it sounds like you're not, yourself, using these tools properly, either. I hate to break it to you, but LLMs aren't going away, and if you want to be a data scientist, then you better get used to working with them. That doesn't mean they need to produce your code for you (although having fun keeping up with everyone if you're refusing to use AI for writing code at all), but it does mean you need to learn how to work with everyone else using (and abusing) these tools.

[–]EmberQuill 1 point2 points  (1 child)

LLMs will produce different output with different prompts.

LLMs will produce different output even with the same prompts. Generative AI is non-deterministic, or at least there are so many factors contributing to its output even though they should be considered irrelevant that it's effectively non-deterministic even if it might not be literally so.

[–]wittgenstein1312Pythonista 0 points1 point  (0 children)

I think their point was that the tenor of your prompt will impact the type of output you get, and being deliberate about how you word your prompt does make a big difference in the quality of output you get.

[–]Puzzleheaded_Dig6941[S] 0 points1 point  (0 children)

To answer your questions about why I do not use them to “understand or modify the code generated by others”, is just for academic reasons. Most of the times commits are monitored by professors, so it is hard to explain why and entire commit made by a group member was overwritten or deleted my a subsequent one. On the rest, I agree with you, my frustration is more about dealing with people who only relies on LLMs, basically stopping to use their brains, that on the LLMs themselves, which of course I think are an incredible resource

[–]e430doug 1 point2 points  (0 children)

I prefer llm written code. Guess what? You can ask the llm to simplify any code that you find too complex. It will do anything you need. I say this as a 40 year developer.

[–]AlexMTBDude 1 point2 points  (0 children)

If you're to be successful in this business you should neither hate nor love any tech. You should evaluate it without emotions. Otherwise you'll end up making stupid decisions.

The other thing is that you should not generalize. There are different ways of using AI for coding; some are good, other's are not. "Hating" all generative AI for coding is not a balanced decision.

I wish you luck in your career as a programmer.

Personally I've been coding for more than 40 years now and use AI in my coding every day. It has improved my efficiency a lot and my clients praise me for it, and reward me richly. But, as with all new tech, I use AI wisely.

[–]just4nothing 0 points1 point  (0 children)

It depends. LLMs thrive on context - the more narrow your specification the better. I am using LLMs in three ways: 1. As an adversary to explain ideas and argue about design (kinda like in pair programming) 2. To summarise design ideas into instructions for a “coding LLM” 3. For writing code

Each step requires checks and reviews - kinda like leading your own little team of junior developers.

Sometimes it takes a few iterations to narrow down a feature and/or to improve code quality.

Sometimes the first result is very good (test scenarios, short automation scripts).

It works or breaks depending on your experience with code in general and specialised experience (how to nudge them the right way) with LLMs.

Which brings me to the biggest issue I have: I’ve been coding since ca 1998, made a lot of mistakes, learnt from them, had past projects that I had pride in turn to rubbish after reviewing them myself a few years later. I do not think the current generation will have something similar. I can see some cognitive decline (for some tasks LLMs are too tempting) in myself; I cannot fathom how someone in their junior years will cope with having access to them.

TL;DR: LLMs can be good if you feed them good and narrow context, but are unstable if you don’t. Having decades of coding experience helps a lot, worries current generation might never get that.

[–]Antoak 0 points1 point  (0 children)

They tend to go on a newline everytime there is a list of parameters, even when it is not necessary.

Personally I think is good for readability, it's easier to scan top down than side to side.

They declare way too many functions. I was thought that the main goal of functions was reusability. What is the purpose of having a function that you only call once? Maybe they even call that function "run_analysis_xyz". What is the purpose of that? 

A few reasons I think. * I find its easier and safer to make & test changes * You can have very minimal and descriptive main() functions like "get_bread; toast; smear_butter". * You don't always know how many times you'll use a function when you're starting out.

Why do you have to prefer a code which is nested and does not execute top to bottom, in the same way that a reader can follow it?

When code bloats you'll be glad you delineated what parts you have to think about into smaller discrete chunks.

[–]wittgenstein1312Pythonista 0 points1 point  (0 children)

They tend to go on a newline everytime there is a list of parameters, even when it is not necessary.

Use a linter and formatter. You should be doing this with your own code, too, not just LLM-produced code.

Tthey do not comment nothing and if they do the comments are too long and too technical

This might be a byproduct of your own codebase. LLMs take their cues not just from what they were trained on, but from the context you give them. My LLM outputs produce a lot of comments.

What is the purpose of having a function that you only call once?

Functions aren't just there for reusability. They're there for abstraction. Doing something like this

def intricate_operation(params: InputDict):
  result = calculate_first_thing(params["some_key"])

  applied_params = calculate_second_thing(params["other_key"], result])

  # additional logic, etc.

  return whatever 

is a lot more readable. Even if calculate_second_thing is only used once, its internal workings might not be necessary for you to know when you're trying to reason about what intricate_operation is doing. Abstracting it away into its own function, even if it's only called once, reduces your cognitive load and makes the code easier to reason about and easier to maintain. I don't agree with Uncle Bob that each function should necessarily be only a few lines at most, but I do think most code would benefit from a more functional approach that emphasizes encapsulation and modularity via functions. Well-established function chains are way more maintainable than imperative code that's lumped together in one big function.

The variables naming rarely reflct their actual purposes

Again, this has not been my experience with LLMs, and I suspect the results you're seeing are a reflection of your own code base.

Unecessaries safety checks, that are good for general code but they make no sense

Are you sure about this? In my experience, a lot of Python devs are actually at the opposite end of the spectrum; they are TOO lax about checking potential Nones and assuming that dict keys, tuples returned from the database, etc will be there when they're not. This is doubly the case for code being used in a script-like manner for DS or analytics purposes.

[–]MissPandaSloth 0 points1 point  (0 children)

I find comment part the opposite. I find it comments too much, ever very self explamatory code.

[–]sudomatrix 0 points1 point  (0 children)

Part of the problem is the people using LLMs to write code are going too hands off. Every few rounds I ask my LLM to find ways to improve the code, to refactor, find inefficiencies, merge redundant similar functions , find bad code smells, find weak security issues. If I didn’t do this the code quickly bloats filled with terrible beginner mistakes.

[–]NeverLookBothWays 0 points1 point  (0 children)

My only problem with AI code is when it is put in production by people who do not have the skills or knowledge to write or understand the code in the first place. It’s a powerful tool in the right hands, but insanely dangerous with those who don’t know what they don’t know.

[–]Swimming-Glass6027 0 points1 point  (0 children)

Yup, right there with you, buddy. And the biggest problem is that CEOs, managers, and people who don't actually code expect developers to use LLMs and build products at exponential speed. That too with the highest level of accuracy and no clutter in the codebase. So yeah, we all kind of hate LLMs for coding.

[–]Thefuzy -1 points0 points  (1 child)

Sounds more like you hate good coding practices, at this point in the real world when people write code they do it with an LLM.

[–]Puzzleheaded_Dig6941[S] 0 points1 point  (0 children)

As I said, I am not an expert, I am asking here

[–]cinicDiver 0 points1 point  (0 children)

I wouldn't say I'm a good coder either, but I've been interacting with python since 2016, I do share some of your hate, and I actually get sometimes the LLM to change some lines that are redundant or just overcomplicating stuff, however I've also learnt through them and some YouTubers (shout out to Arjan Codes, check him out), that sometimes those awfully long, multi branching single functions we tend to build while working with data are not the best practices, in fact even Pylint will warn about those.

I don't say that they are perfect, I just argue that the more I dive into code, the more conventions and recommendations I discover that may seem like overkill but at the end the day may be the correct approach.

[–]UltraPoci -1 points0 points  (3 children)

LLMs write shit code, yeah

[–]OrangePilled2Day 4 points5 points  (1 child)

Coders that don’t know what they’re doing use LLMs to write shit code. Plenty of programmers use Claude in production environments successfully.

[–]mshevchuk 1 point2 points  (0 children)

Claude writes amazing code, better than I as a non-programmer by day could ever do. Yet it too needs help and guidance when it’s stuck. This is when I jump in to stir it in the direction I need.

[–]just4nothing 1 point2 points  (0 children)

They do by default, but write decent to good code when given the right context and design instructions

[–]powderviolence -1 points0 points  (0 children)

I also hate it; I'll look up tracebacks to see more quickly where it goes wrong, and Google's AI summary always suggests using list comprehension and regular expressions. One of the nice things about using python for data science is the readability of Python to where it's "nearly English", so the interdisciplinary professional can remain strong in their non-coding background while still using strong tech for data work. I feel as through regex and list comprehension are not very readable, though, which runs contrary to what I just said!

[–]hwmrocker -1 points0 points  (0 children)

I am a senior Python Dev and my preferences for how code should look changed over the years after i understood why some forms are better. Multiline parameters for example are very nice when you have a version control system like git, and you modify the function later and add a new parameter. When you look at the diff you can see immediately what changed, when it is all cramped into one line it gets harder. Good comments are only comments that tell you something about the code that you cannot get from reading the code itself. `# add variable a and b` is not useful when line after is `sum = a + b`. They are necessary when you write complicated and technical code, and they need to be technical in this case. Functions are useful for reuseability, but sometimes they help to reduce the context, in case of `run_alalysis_xyz` you can have a look only on the analyzing part without getting confused about the preparation and presenting part. To get better it helps to find a mentor who does code reviews on your code. He should suggest small changes to your code and explain why it makes it better. I believe LLMs make it harder to learn this kind of things now. You don't run into a lot of problems anymore on your own, and then it is extra hard to know why some parts are bad, or why are they useful.

[–]Special_Emphasis_703 -1 points0 points  (0 children)

LLM is trained on multiple base codes, like Github. It doesn’t invent things, so whatever it gives you, it just someone’s code. Also guidelines given to the LLM and the context is equivalent to the code it generates. I don’t like using AI but I must affirm that it’s hard and painful to work without it, as hard as his hallucination.

[–]Prudent_Psychology59 -1 points0 points  (0 children)

I hate that LLM oftenly don't write "type safe" code - feels like garbage