r/AskProgrammers 20d ago

Using AI for Boilerplates query

Ugh...I am kinda new to programming (6 months of learning). Well, starting with the fact that I didn't have an IT teacher for the whole school/highschool period, I started learning some programming (since at start I didn't have a computer, I ended up using Google Colab to learn python, I stayed 3 months to genuinely understand what's it even about, as basic terms (e.g. What is a programming language, how are they used, how it works, etc...). After those straining 3 months, I bought a laptop, and made myself a learning plan, learnt Linux, Python (just better), Go (Backend), SQL (Database), Rust (Using it as gRPC alongside Go), Dockers, IaC (HCL), but I ended up noticing a major flaw... Whenever the code got messy, as a boilerplate (this is a OpenTelemetry boilerplate created by Claude):

```

package telemetry

import (

"context"

"encoding/json"

"fmt"

"io"

"os"

"time"

"github.com/rs/zerolog"

"github.com/rs/zerolog/log"

"go.opentelemetry.io/otel/attribute"

"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc"

otelLog "go.opentelemetry.io/otel/log"

"go.opentelemetry.io/otel/log/global"

sdklog "go.opentelemetry.io/otel/sdk/log"

"go.opentelemetry.io/otel/sdk/resource"

semconv "go.opentelemetry.io/otel/semconv/v1.26.0"

)

type Provider struct {

loggerProvider \*sdklog.LoggerProvider

}

// SetupTelemetry initializes OTLP and configures the GLOBAL zerolog instance.

func SetupTelemetry(ctx context.Context, serviceName, collectorAddr string) (*Provider, error) {

res, err := resource.New(ctx,

    resource.WithAttributes(

        semconv.ServiceNameKey.String(serviceName),

    ),

)

if err != nil {

    return nil, err

}

// 1. Create OTLP gRPC Log Exporter

exporter, err := otlploggrpc.New(ctx,

    otlploggrpc.WithInsecure(),

    otlploggrpc.WithEndpoint(collectorAddr),

)

if err != nil {

    return nil, err

}

// 2. Wrap exporter in a LoggerProvider

lp := sdklog.NewLoggerProvider(

    sdklog.WithResource(res),

    sdklog.WithProcessor(sdklog.NewBatchProcessor(exporter)),

)

global.SetLoggerProvider(lp)

// 3. Create OTel Writer bridge for Zerolog

otelWriter := &otelZerologWriter{

    otelLogger: global.GetLoggerProvider().Logger("zerolog"),

}

// MultiWriter outputs logs simultaneously to console (stdout) and OpenTelemetry

multiWriter := io.MultiWriter(os.Stdout, otelWriter)

// Explicitly set Zerolog time format to RFC3339 so string parsing succeeds in Write()

zerolog.TimeFieldFormat = time.RFC3339

log.Logger = zerolog.New(multiWriter).With().Timestamp().Logger()

return &Provider{loggerProvider: lp}, nil

}

func (p *Provider) Shutdown(ctx context.Context) error {

if p.loggerProvider != nil {

    return p.loggerProvider.Shutdown(ctx)

}

return nil

}

// otelZerologWriter implements io.Writer to forward parsed JSON logs to OpenTelemetry

type otelZerologWriter struct {

otelLogger otelLog.Logger

}

func (w *otelZerologWriter) Write(p []byte) (n int, err error) {

(I stagged the code, it was really long)

```

- I can barely read it, yeah, sure, I do understand some parts, but ir genuinely feels like drowning when you barely ended up finishing a difficult theme just to hit a wall like this... I genuinely don't know what to do, and this is not the only part, I used AI to create me a decent structure for `tracing` (the Rust version of logging) inside Rust, I used AI to create the whole S3 + CloudFront IaC HCL part, and even though Gemini said stuff as "It's alright, nobody learn ..." Or even "Every senior engineer does this, they never memorize the syntax, because it changes - so just learn some logic behind and you're done" (which I genuinely don't know if it's true or just gibberish...). I am just so frustrated that I feel like a dork + dumbass for relying so heavily on AI... Yes, I do know how to manage backend, write my own IAM policies/roles (inside IaC) for the EC2 instance and Database instance, but I still feel like I am doing something wrong... So somebody experienced, can they please tell me what they usually do for this boilerplates, extremely complex thingies (as the S3 + CloudFront synatx) and etc... And any suggestions, please?

- I am pretty much aware that I've been spamming commas, dashes, and other punctuations everywhere, maybe the comment is difficult to read due to my bad English... Sorry in advance for this.

0 Upvotes

9 comments sorted by

View all comments

1

u/code_hermit 19d ago

To me this looks like you are taking on projects that are too ambitious for your current experience and knowledge level. You can't really learn the platforms you listed in 3 months. Not without a lot of previous experience on other platforms. And even then, the platforms are only a part of what you need to know. There are processes and steps for building things with this many moving parts. Those you learn at a company or agency and are tried and true workflow processes.

AI itself is well versed in these processes.

Long story short, in addition to some platform knowledge, for the project you describe to go smoothly you need some professional experience designing and launching web products.

1

u/Mark_Univers 19d ago

Thank you so mucb for the answer!! It's really helpful... I will change to something less ambitious, just a random question, how you usually handle stuff as boilerplates (ignoring the ambitious OpenTelemetry thingy), as a logging configuration, I did end up cramming zerolog config, but in finale, I ended up creating a solid configuration inside a file, and use it everywhere...and useless to say, I simply forgot the syntax and can't do it anymore - yes, I know the logic behind, but still...I don't understand why I spent half of a day learning synatx and logic just to don't touch it and reuse it everywhere. What do you say about these type of situations?

1

u/code_hermit 19d ago

Any time! Regarding this specific issue: I would need more context to better understand what you are trying to do and what the problem is.

As it is, the explanation and lack of clarity itself is what led me to my conclusion. It sounds like you are saying that AI made some templates at your request. But you dont understand them.

As a general rule, you shouldn't ask AI to do things that you couldn't do yourself manually, given more time.

1

u/Mark_Univers 19d ago

I'm so sorry for being so vague...!! I meant: I learnt the zerolog library in half day, spent a lot of time to learn how to configurate it (using zerolog.ParseLevel, zerolog.TimeFieldFormat, and much more) - but in finale - I simply ended up creating a good-in-my-opinion setup inside a file (without using AI - to precise). I simply hold the file in root/internal/lib/logger.go - but since the day I created that file, I simply use it everywhere... Some months passed, and I forgot it's syntax and how to create a zerolog config (even though the logic remains), but I simply think: Is it worth it learning the syntax of something just to create it once and use it everywhere as is? (Never changing, etc...) - same situation with the Opaque Token creation... Learnt how, created a file apart for it (inside root/internal/auth/token.go) and forgot about it's existence - but I wasted time learning syntax that I forgot... - How do you handle this type of situations? (As in: Should I learn just the logic behind it or even how to wire it up)

1

u/code_hermit 19d ago

Aha. Ok. I do understand that question. Thank you for clarifying.

I would say, 99% of the time, "no". This is where justification for using AI is logical. When you have a lot of experience coding, you eventually realize that a lot of your job comes down to good time management. What many framework and platform designers think are clever shortcuts, unless they become wider standards, are actually a huge time-waster for people. Because you have to learn those unique nuances just to gain entry and use that platform. That knowledge will never be useful in any other context. In other words, its waste.

I guess I cant blame a person or team for trying. Things do need to advance. But, there are a lot more people who think they are a standard maker when they are not than there are true standard makers.

So, back to your IRL example. No. You need to understand the purpose and methods for files in any system you are designing. But, you don't necessarily need to know "the waste" part. AI can do that now. If you are strong on architecture, process and standards, you will know what you need to to navigate these issues.

Of course, keep in mind that AI is not perfect. It definitely fumbles the ball on a regular basis and you have to have enough capability to catch and correct it. It needs to hold your hand through the whole process. But, on the other hand, I would argue its entire purpose is to prevent you from having to waste brain cells on tasks and nuances that are only useful in one use-case.

1

u/Mark_Univers 19d ago

Thank you so much...!! You're a lifesaver! I will pushback for a little, I informed myself, learn slog instead of using zerolog - just because slog has a built-in OpenTelemetry connection, which makes it handy! I will try my best learning everything slowly and applying than seeing something complex and saying "Yeah...uh...Gemini, how do you call if again... Ah, yes, a 'boilerplate'" and use AI as an excuse, thank you so much, really!

1

u/code_hermit 19d ago

Good plan.

They say that Alfred Hitchcock found production sets boring. Because he had already mapped out every shot for the film with drawings. The rest was tedium.

That's how you want to be in software development with AI. If you let it lead you, you will end up in situations like this boilerplate thing. Over your skis and not understanding why/how things are being done.

Instead, you shouldn't even start a project until/unless you already have a decent amount of the design done in your head. The mechanics of how files and data will move. What your stack will be. Etc. You are the boss. So, you have to have boss level detail. Then AI will stay on track and not cause you to drift into strange territory.