Live data from Hacker News

Are software engineering “best practices” just developer preferences?

floverfelt.org

191–200 of 369 posts

Re: Are software engineering “best practices” just developer preferences?

#191

Earlier quoted context omitted.

Getters and Setters also permit you to specify that something can only be retrieved or assigned, but not the other. This is non-trivial in most programming languages so having this as a common pattern is useful. Though I like C#'s properties versus seeing a bunch of getFoo and setFoo methods running around, if Java had provided the same or a similar capability there would probably be no controversy. It's the noisines…

> Getters and Setters also permit you to specify that something can only be retrieved or assigned, but not the other. Only retrieved? `final` and set the fields through the constructor. Sure someone could implement setters-only if they wanted that. Except I’ve never seen it and get/set are always used instead. Just one layer of indirection for no benefit.

That's not equivalent. You may want a field to be updated by other actions. That is, its value is derived from the other properties of the system. You could recompute those on each request, but that's potentially costly. You could also recreate the entire object with each small field change. That's also very costly.

Consider a collection class which has a size field. `final` would be the wrong thing to use. If you expose the size field but make it final, well, it's immutable and your entire collection is either lying or also immutable. If you expose the size field but it's not final, then anything can alter it. Consequently, a getter (the concept of one at least, see C# again for a cleaner approach than what Java did historically) is useful and then when another element of the interface is used (adding or removing elements) the size field can be updated appropriately. The next time it's retrieved, it's correct and you don't need to recompute it.

This kind of thing can be a consequence of many other systems, a collection is just sufficiently universally understood that it's a good example of the concept.

Re: Are software engineering “best practices” just developer preferences?

#192
post #162

> Java is infamous for its verbosity. [...] This paragraph highlights something I've been saying for ages. Most criticism of Java needs to be directed towards Java programmers and not the language itself. The language allows you to simply make a class. You're not required to make an interface and then make a class that implements it, and yet, Java programmers do it anyways and then criticize the language for being ve…

> Getters and Setters? You probably don't need them. Classes can have public member variables. The getter / setter debate and public fields is about exposing the internal implementation of the object (and thus making it unchangeable without breaking other code) and being able to reason about where the internals are used (if you do need to change them). For example, if I've got a java.util.Date exposed as a public fie…

Apparently your field was used both for some internal shenanigans as well as a public field through the get/set indirection. Then you changed the field but kept the old public behavior. I wonder whether (1) that dual purpose internal/public role was wise to be begin with, and (2) whether that change of the internal logic of the getter might have just papered over a more significant change.

It might be good if a change just breaks client code. The client expects just to get/set something: they might not expect that some update migth add arbitrary logging or internal logic (like setting this value will also set another value, but we won’t tell you).

Most of the get/set stuff that I see are for value objects with either no or little business logic. Simple value objects _should_ just expose their implementation.

Re: Are software engineering “best practices” just developer preferences?

#193
post #156

Earlier quoted context omitted.

Calling yourself an "engineer" involves licensing fees, continuing education, and the most fun of all - a university degree. Some jobs require you to be a member, but most of these jobs aren't in software. So most software people I know just use adjacent titles like "developer" or "designer". It's essentially the same job - just without all the extra responsibility. The word "engineer" has a certain social clout to i…

On the upper end (probably even in the middle) software developers earn more than licensed engineers. I'm pretty sure your mom can brag about her child the developer making 3x what her friend's child the engineer makes. There are engineers who end up moving to software for just this reason. Software is super important and becomes more so over time. I'm not sure why being proud of being a developer isn't enough and wh…

Yeah, titles are a strange thing. There are a lot of PhDs out there earning bupkiss, but they're still "doctor"s, and that carries a certain respect.

I agree it's mostly BS and doesn't make much sense, but I could say the same for much of reality...

Re: Are software engineering “best practices” just developer preferences?

#194
post #46

Right, but have you ever worked in a place where no practices at all are being followed? Where there are hacks after hacks, giant classes with giant methods, no interfaces, static methods, bad names everywhere, you need to find a bug? good look, you want to write a test to avoid regression? Ok that would take you 5 times more time. I agree, following a “best practice” without understanding the “bad practice” that it’…

> But just discarding best practices because no one understands the reasons behind is also silly.

So what do you do with a "best practice" that doesn't make any sense to you? Do you just keep doing it forever because you can't understand why anybody would invent it in the first place? To take an example I'm familiar with, there's a good chance if you don't understand a Java OOP best practice it's because you've never encountered the problems it was designed to cope with. The OOP design principles that came out of the 1990s and became orthodox in Java around the turn of the century were built to solve the problem of scaling monolithic application development to teams of dozens or hundreds of developers. You would have dozens of people, imperfectly coordinated, hacking on a monolithic codebase for an application that was released quarterly (if that!) and ran on servers that cost more than the CEO's car. The coding style innovations of that era naturally focused on coming up with more and more ways to add layers of protective abstraction, and on training programmers to add those layers to their code no matter what, even if it doesn't seem worth it because 99% of the time, if somebody didn't understand that it was worth it, it was because they were inexperienced and hadn't lived through a horrific integration debacle that delayed the quarterly release by a month.

In my opinion, if your problems don't resemble those turn-of-the-century enterprise monolith problems, then you shouldn't program in turn-of-the-century OOP style, and you should take "best practices" from that era with a huge grain of salt. You should only use them if you can see how your codebase will benefit from them.

Even Java, the bastion of OOP conservatism, is acknowledging that "best practices" are relative by adding record classes. Record classes are first-class language support for violating the best practices that were drilled into generations of Java programmers!

(There are people who do have those turn-of-the-century enterprise monolith problems, for example, library developers! They ship their changes to hundreds or even thousands of people they've never met, who don't keep up with project updates, and who don't budget time to deal with breaking changes. So a lot of the ideas turn out to be really valuable! Just not for, say, small teams building microservices.)

Re: Are software engineering “best practices” just developer preferences?

#195
post #110

Eh, kinda. Calling something a "best practice" is basically an appeal to authority. It means, "this is the right way to do things, for reasons I don't have time to explain." There are times when that's appropriate. But really, "best" and "right" are highly situational. Any rule of thumb, even the most basic and uncontroversial, has a situation where it doesn't apply. I was part of a discussion on a mailing list years…

> somebody got flamed harshly when he mentioned using a global variable.

Harsh bashing on global variables is such a dumb thing.

Yes, they can be dangerous. Yes, many had problems due to using them. Yes, we should tell beginners to avoid globals.

But there is no reason to ban them altogether. Experienced programmers should utilize them whenever it makes sense (instead of passing down a value of a local one to almost every function [sic]).

Re: Are software engineering “best practices” just developer preferences?

#196
Short answer: No, they're not.

Longer answer: I'm confused by the examples given. Nothing there is a best practice IMO, they are only opinions.

This writer is confusing "use git" or more basically "use version control" with the how's and why's underneath. Everything beyond "use it" is an opinion, with multiple "best" options depending on your desired workflow or requirements.

Same for Java - the senior explained why this version of "best" is best for them, but the real best practice of "define your interface as a contract" is hidden behind these opinions.

Contrast this with the civil engineer used as an example, who might say "use a safety factor of 3x rated weight for all fasteners" as their best practice. Using fasteners rated at 2x is a violation of that, but using screws vs bolts vs adhesive are all opinions and depend on the particulars and preferences of whoever is doing the work.

Re: Are software engineering “best practices” just developer preferences?

#197
post #110

Eh, kinda. Calling something a "best practice" is basically an appeal to authority. It means, "this is the right way to do things, for reasons I don't have time to explain." There are times when that's appropriate. But really, "best" and "right" are highly situational. Any rule of thumb, even the most basic and uncontroversial, has a situation where it doesn't apply. I was part of a discussion on a mailing list years…

> He then explained that he was working on an embedded control system for cars and all the variables in that system were global.

Everyone should write Embedded at least once. It's a completely different world.

Re: Are software engineering “best practices” just developer preferences?

#198

I hate the expression "best practice", it's so, so often used by someone to justify applying cargo cult without actually understanding why. "Hey why are you having a try-catch there, it seems like it's just gonna break our stack trace and we don't even graciously recover from it" - it's best practice "Hey why are you using model/view/controller folders?" - it's best practice "Why are you building microservices?" - be…

Same with Clean Code, SOLID, DD SOLID is especially funny because majority of developers doesn't understand / can explain it, let alone have read papers e.g [0], except maybe S letter, yet everybody acts like they do SOLID*. Or Clean Code's small function craziness or misinterpretation and going into "avoid comments" approach * - unless you ask for details [0] - https://www.cs.cmu.edu/~wing/publications/LiskovWing94.…

So the only caveat I would put on that: it's useful to have common language for things, my threshold is that you understand why things are this way.

It's useful to tell someone: "you should have that thing in another class because it's clearly another responsibility", and have a debate on the responsibility itself ; or even on the merits of having a single responsibility per class.

What is not useful is when someone will start making monofunction classes that are 10 lines long on the hotel of "smaller functions are better" and sticking to that because "it's a best practice" with no better argument.

Basically my point is: if you understand what you are doing, great, use vocab all you want. But don't use it as a justification.

Re: Are software engineering “best practices” just developer preferences?

#199
post #92

Earlier quoted context omitted.

Microsoft lost their appeal in Quebec https://www.oiq.qc.ca/en/media/pressReleases/Pages/default.a...

That's interesting, thanks for sharing! INAL; it seems, to me, difficult to enforce. You're not allowed to call yourself an engineer but you can still practice as one as long as you call yourself a developer. What's the difference? In practice... very little. Most developers I know do all the things professional engineers do. Unless the government wants to step in and say that you're not allowed to release software w…

In this case, I think the enforcement wasn't on the people using the tittle. Rather it was on Microsoft "granting" someone the tittle of "Engineer".

"Microsoft Corporation announced in May 2001 its intention to stop using the term engineer in Canada in the title Microsoft Certified System Engineers - MCSE."

Going against the individual professionals for using the tittle might have been harder. Some are probably real engineers or have received the certification but don't necessarily advertise themselves as engineers...

Re: Are software engineering “best practices” just developer preferences?

#200
post #60

> How can Software Engineers call themselves engineers when there’s no rules, governing bodies, or anything to stipulate what true Software Engineering is? We call ourselves software developers in Canada. According to Canadian engineering[1]: The "practice of engineering" means any act of planning, designing, composing, evaluating, advising, reporting, directing or supervising, or managing any of the foregoing, that…

I've met Canadian Software Engineers who referred to themselves as Software Engineers...
Post reply on HN