Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Volguus
Mar 3, 2009

zootm posted:

This is not a good example of bad naming in Java, and there are lots of good examples.

May I please get some? Been using it for so long, I've never had a problem with Runnable->run, Thread->start, Cloneable->clone (even tho clone is part of Object).
And I don't remember ever seeing a bad naming example in Java.

Anyhow, back to the topic, here is my code that I found in an application I was tasked to maintain (fix bugs):
code:
string cmd="del \""+myDoc.get_path()+myDoc.get_filename()+"\"";
system(cmd.c_str());
This code was in a C++ application. What kind of a monkey executes a system command to delete a file? Windows (and just about any other OS) is written in C. One could think that there MUST be a better way to delete a file, other than spawn a brand new process and the associated headache (did it succeed?if not, what was the error? what do i tell the user?,etc.)

Anyhow, the rest of the code was just as bad. I want those 2 wasted months in my life back.

Adbot
ADBOT LOVES YOU

Volguus
Mar 3, 2009

Avenging Dentist posted:

Or you could use something called "namespaces" and allow people to apply using declarations to minimize verbosity. A radical idea, I know.

Am I weird for not finding those names...bad? I don't see the problem with a 20 character long class name. I mean, I would have had such a problem back in Borland C++ 3.1 days, but today, with today's IDE's, its all a CTRL+space away.

Volguus
Mar 3, 2009

Avenging Dentist posted:

Yes. You are weird. It's not even about typing them, it's about reading them. Anything nontrivial with any of those functions (and given Java's propensity for verbosity, that's 99% of things) is going to be spread out on multiple lines or will just scroll horizontally off the screen. A good sign that your code is poo poo is when a majority of the individual statements have to wrapped to fit on the screen.

Aha , I see it now. So at the end of the day its just a matter of taste.
I hate it when I see cryptic code, even if it has comments. I love it when I can "read" the code, even without comments.
And no, don't give me the 80 columns crap. Nobody nowadays has an 80 col limitation, upgrade your drat monitor if you do, so no, there is no need to wrap on multiple lines most of the statements.
If you can't upgrade your monitor and are forced to use an 80x25 screen...don't do Java. Plain and simple. Most likely the stuff you're doing (with those limitations) is not appropriate for Java.

It is just a matter of taste. Even though I program in C just as much as I do in Java, I like the Java style more. I like to comment the algorithm used, not the fact that I just wrote in one line the most complicated code ever.

So , sorry sir, those class names are fine.

Volguus
Mar 3, 2009

biznatchio posted:

So what advantages would I have for choosing Perl 6 for a new project being started today over, say, a language that exists?

As usual, the answer to that is: depends on your project.

Perl is a language suited for certain tasks (and here i'm looking at its legendary strong point: regular expressions), and probably not so suited for others.

Can you build a GUI app with it? Of course. Should you? I doubt it.
Especially since PERL-compatible regex libraries have been created for other languages as well (java, c/c++, python i think)

So, at the end of the day, the questions to be asked are:
- Does my project require certain features that PERL would be a perfect solution?
- Who will code it? Do those people know PERL?Do they wanna know PERL?
- Who will maintain it? Does that team know PERL ?Do they wanna know PERL?

Volguus
Mar 3, 2009

Powerful Two-Hander posted:

Not so much a coding horror but some bright spark apparently decided to do some "tidying" on a production db and tried to rearrange columns in a live table using a gui in a db tool.

Predictably this massively hosed up the table and said tool is now banned.

The mystery is, if you don't know what you are doing why would you do this and if you know what you're doing why the gently caress are you drag and dropping changes in a gui?

Edit: And from what I remember you always need to do a drop and rebuild to change column order so it would have hosed up either way.

The only reason I can imagine needing to rearrange columns in a table is so that "select * from table" returns the columns in the desired order, which is a coding horror in and of itself. A simple "select col5, col1, col10 from table" would have accomplished the same thing.

Volguus
Mar 3, 2009

kitten smoothie posted:

From what I gather the generators use the engines to provide power to the plane in flight, and at issue is software in some computer units that manage those generators. I imagine if the engines are powered off maybe there's some battery power unit, or shore power if parked at a gate, that keeps the computers hot.

I've always wondered how the avionics stuff like this works. I guess they don't completely power down aircraft if they're idle overnight or whatever? I can imagine there's not just a set of keys and an ignition switch in the cockpit like your car.

I imagine (I'm not a pilot and I have no idea what I'm talking about) that is more a question of economics. These planes do not turn off. They land on an airport, get the people and luggage off, they board new people and luggage, then they take off. To shut them down would mean to lose money and they only make money while in the air. Given the price tag for one, it would not be surprising that these kind of planes would be (ab)used for 248 days non-stop.

Volguus
Mar 3, 2009

IT BEGINS posted:

It's not particularly offensive, but we're adding a new feature to this code so we were having to move this stuff around anyway. 'enabled ISNULL' was making things unclear, as well as a few repeated nullchecks for "$enabled != 'n'".

You might be right, and I'm not changing it yet. Just amused that the response was 'yeah do this other stupid thing instead'.

Think about it this way: if you make it a boolean, then it can only ever have two values (should be not nullable, of course). If you keep it varchar, then you have TRUE, FALSE and FileNotFound at a later date. What can be more beautiful than that? If it's limited to only one char in length, then you will be limited to 26 states, hopefully you can manage that.

Volguus
Mar 3, 2009
In a java web application (spring based), one developer thought that when an administrator updates a user information (including password), that administrator should enter the original password of the user. That is a WTF in and of itself, but it gets better. So, how do we check if the password entered is the same as the one in the database? You wouldn't believe it (comments are mine):
Java code:
public boolean verifyPassword(UserInfo userInfo, String password) {
	try {
		//original encoded password
		String passwd = userInfo.getPassword(); 
		//a class that creates a new user instance for no reason whatsoever
		CustomAuthenticationServiceImpl cas = new CustomAuthenticationServiceImpl(); 
		// and stores the password
		cas.setPassword(passwd); 
		// the password encoder we are using. It is injected already by spring, and we have it, but why not make a new instance, and tie ourselves to it
		BCryptPasswordEncoder bce = new BCryptPasswordEncoder(); 
		//make a token
		UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userInfo.getUsername(), password); 
		//make a new provider (there is one made by spring already, but hey ... let's make one ourselves)
		DaoAuthenticationProvider au = new DaoAuthenticationProvider(); 
		au.setUserDetailsService(cas);
		au.setPasswordEncoder(bce);
		//and now we actually authenticate the user
		au.authenticate(token); 
		//yepee, we're good to go
		return true; 
	} catch (Exception e) {
		// obviously this means that the passwords do not match
		LOG.error("Failed to verify the password: "  + password); 
	}
	return false;
 }
of course, that entire block of poo poo can be replaced by
Java code:
public boolean verifyPassword(UserInfo userInfo, String password) {
	//use the passwordEncoder instance that we have to check if the passwords match
	return this.passwordEncoder.matches(password, userInfo.getPassword());
}
Still, why does the administrator have to enter the user's original password (why does he even know it???) ... it's a mystery.

Volguus
Mar 3, 2009

Suspicious Dish posted:

I believe it. The dude doesn't know about this.passwordEncoder and instead writes fairly clear and understandable code to check the password instead. You should have just laughed and said "oh, you don't have to write this, Spring injects a service for us that does this" and CR failed it. Then he would have said "oh cool, that makes things easier" and fixed it. And then you wouldn't have tried to make fun of him on an internet forum for him not knowing literally everything about the massive 500,000 LOC Java Enterprise framework he's using.

code:
@Autowired
private PasswordEncoder passwordEncoder;
was defined 5 lines above his method. The controller only had one other service injected. It was used in another method (not written by him, true) . There was absolutely no reason whatsoever to not use it.

Volguus
Mar 3, 2009

Soricidus posted:

can't we just be impressed that this codebase is actually using a non-terrible method for storing passwords in the first place?

Heh...until 3 weeks ago that codebase stored passwords in javascript. Literally
code:
if(username=="X" && password=="Y") {....}
Not to mention that the PasswordEncoder interface only has 2 methods: encode and matches. Pretty hard to miss what they are doing, as they state that clearly in the javadoc.

Volguus
Mar 3, 2009

Ender.uNF posted:

Programming languages never die, they just run in/on javascript.

And it's not even the only one:

quote:

There are several other implementations of Tcl in Javascript ...

Volguus
Mar 3, 2009
Holy poo poo, is the payoff that big that its worth it? This screams "runaway little girl, run away" from kilometers ahead. I mean, to build one's entire stack on something like javascript is incomprehensible to me but understandable when the promised payoff is bigger than the investment. But when that ugly lie is showing its big ugly head ... why go on? The entire show is built on a house of cards anyway. Kill it, shove a stake through its heart and walk away never looking back.

Volguus
Mar 3, 2009
JS like JS. It's a language, it has its quirks and .. oh well, you learn to live with them. But the developers... that's the real WTF. The kids that run the npm showshit, the contributors, the lego "programmers" who write that horrifically wrong line of code that gets published without any oversight and gets used over and over again (because nobody knows any better), that's the real WTF.

And they call themselves developers. Full stack developers. They put that poo poo on the server-side where things like is_int or _is_array should have never been even questions, and yet they are. But .. I'm the old-fashioned one. Why are they even allowed anywhere close to a computer?

Volguus
Mar 3, 2009
Which brings us to the second "flag" you need to know: "man echo" . For more detailed information, you can always check the info pages as well.

Volguus
Mar 3, 2009
There are, yes, numerous verbosity complaints about Java, but the IDEs have largely fixed all/most of them. Any half-decent IDE would automatically generate the ActionListener boilerplate, or the setters/getters or toString/hashCode/equals methods. Java 8's lambdas are, in my opinion, even more dependent on the IDE, since it is not clear from the code what type of argument the lambda gets.

As for reading it, that comes down only to practice. I find reading Python code quite the workout, for example. Is this line belonging to this block or the one above it? Is that a space or a tab or are my settings messed up? Did you mean to put that space in there or was it a mistake? What does this module do? Just like in Java 8: "lambda event: do something", what is that event? What members does it have and what can it do for me? Without an IDE I am completely lost.

Volguus
Mar 3, 2009

feedmegin posted:

Doesn't help with the complaint about reading the code though. Plus, to my mind a language that requires an IDE to generate massive chunks of code for you to be usable is not a very good language.

You'd hate C++ then. Or, not to mention, C.

Scala ... eh, is an interesting language, but when reading some gibberish code and then trying to google for it to see WTF is that thing doing and the search returns no results, what does that say about that language then? And about the IDE hate: what year are you living in? Without syntax coloring or some modicum of autocompletion or at least helpers and hints every now and then ... it sucks, doesn't matter the language. I wrote code in Turbo C++ on a monochrome monitor back in early 90s, I don't wanna do that again.

Volguus
Mar 3, 2009

feedmegin posted:

My day job is writing C++ and it doesn't involve an IDE generating anything, nor is the codebase I work in excessively verbose. Why would you think it did?

If you think that Java is more verbose than C++, well, I don't know what to say. Though, is it true, code generation in C++ from an IDE is even now in infancy, compared to Java/C#, so you can't do that even if you wanted to.

Volguus
Mar 3, 2009

leper khan posted:

Lolwhatareyouonabout.

Java doesn't even have variadic templates.


e:
void iSeeYourPoint() {
}
void iSeeYourPoint(int this) {
}
void iSeeYourPoint(int this, int is) {
}
void iSeeYourPoint(int this, int is, int clearly) {
}
void iSeeYourPoint(int this, int is, int clearly, int less) {
}
void iSeeYourPoint(int this, int is, int clearly, int less, int verbose) {
}

It doesn't have variadic templates, but it does have variable arguments:

void iSeeYourPoint(int... noneedfor100methods) {
}

Volguus
Mar 3, 2009

I hope not. That's simply stupid.If it contains "extreme" in the name ... its probably safe to not follow.

Volguus
Mar 3, 2009

necrotic posted:

Good point... I've been targeting senior so I'm in that mindset. And we do not do crypto. To be fair it's not an immediate no but a good indicator for most folks.

Unless your entire job is writing a crypto library/toolset. And the position you're hiring for is a crypto expert that can help you get "to the next level" (whatever that may be). In that case, "don't roll your own" is obviously the wrong answer.

Volguus
Mar 3, 2009

canis minor posted:

Taken from SO

code:
function round(num) {
    return +(Math.round(num + "e+2") + "e-2");
}
it works, but it makes my skin crawl

What? How? How does that even remotely work? JS is full of lovely "magic-tricks" but this one takes the cake (and I'm aware of the truth table).

Volguus
Mar 3, 2009

xzzy posted:

As long as javascript remains a dominant player json ain't going anywhere.

Isn't this more about how garbage the parsers are and less about how lovely json itself is? While I haven't read the RFC, in common usage json doesn't come as being inherently flawed, unlike yaml, where the tiniest mistake (wrong space or tab) breaks the entire thing.

And about JS: are the existing JS engines so performant that nobody wants to replace them? Even chrome doesn't come with a native Dart engine (it did in a developer edition). Or Edge with Typescript. Everyone just compiles to JS, like is the holy loving grail of languages.

Volguus
Mar 3, 2009
All this voice recognition stuff ... Bullshit. What we need is the ability to just think and the computer to just do: https://en.wikipedia.org/wiki/Brain%E2%80%93computer_interface . With a bit more research we can overcome whatever barriers exist right now in BCI to be commercialized. That's where the future is.

Volguus
Mar 3, 2009
99 is XCIX in roman numerals since you're not supposed to have more than 2 levels of difference between letters. IC, while shorter, breaks that rule since you have 4 levels between I and C.

Volguus
Mar 3, 2009

QuarkJets posted:

I've been forced to work with some project that uses the Matlab compiler to create a standalone executable for running on some batch nodes, and randomly about 1% of the time the executable just crashes as it's launched. I assumed it was some issue with the code, but the crash occured suspiciously fast and didn't leave behind any useful information so I began to wonder if maybe I was using the compiler wrong.

Looked around online and apparently this is a common problem with Matlab-compiled standalone executables, there is no solution and you just have to deal with it

The solution is that Matlab should not be used in production. It's awesome for the research phase, but when the research is over, implementation for the product should be done by a developer in whatever language the product is going to use.

Volguus
Mar 3, 2009

New Yorp New Yorp posted:

DI is a method of implementing IoC. It's just a way of solving the problem "I want to test a thing that gets data from a web service/database/other complex component without actually involving the web service/database/other complex component" or, "I want this thing that gets data from something else to be able to get data from any number of something elses based on some set of criteria, without altering the logic of the thing".

My way of looking at it is as follows: "In order to do my job I need an instance of X. Someone give that to me."
In the example presented above, Foo needs a Bar to be able to do its work. It explicitly asks for it in the constructor, and Main provides it when it makes a Foo. What DI frameworks do is provide that automatically (via the magic that is also known as reflection). All that Main has to do is tell the DI framework: whenever anyone requests an IBar give them an instance of this Bar object. That's all there is to it.
But then, you can't go and say "new Foo()" anymore. You have to go to the DI framework and ask it to make a Foo for you. Then the DI framework will take care of providing all the required dependencies that Foo asks for.

Volguus
Mar 3, 2009

RandomBlue posted:

Frankly I hate "magic" things that just happen. It obfuscates what's actually going on and makes it much harder for someone unfamiliar with that type of magic or a particular code-base to actually understand what's happening for very little actual gain. You've saved yourself having to pass in a constructor parameter?
.....

It shouldn't obfuscate anything in a properly designed library. But I agree about .Net. I had the "pleasure" to work with it in the last 6 months or so. Coming from C++ and Java, C# looks like a better Java. It is a better language no question about it. But (and here is when the fun comes in), everything in the .Net ecosystem, the tools, the libraries, the frameworks, look like an undernourished child from Somalia with Down syndrome that was just rescued by a compassionate person when compared with your normal, healthy and properly fed (almost obese) Western boy (Java).

It's not even funny. Why do developers subject themselves to that abuse? C#'s superiority over Java at the language level is not maintained everywhere else. Not to mention Microsoft's almost comical tendency to make everything 100 times more complicated than it needs to be, then turning around and instead of fixing the old library, just releasing a brand new one with different (but just as bad) problems than the one before.

Volguus
Mar 3, 2009

RandomBlue posted:

Overall though, Java is pretty nice for cross-platform work since JavaFX was made available, but Java seems to have a huge image problem with the public perception of it still based on how things were 10+ years ago when Java apps used Swing and looked horrible and the performance wasn't great.

Oh, you're talking about java desktop. That's not its strong point, it never was. I've done my share of swing and javafx applications in the last 20 years (and they're really nice and fast frameworks once you get to understand them and learn how to use them) but my advice would be to just not do it if you can help it. The image perception is not something you can change overnight, and the expectations change daily.

Use java for the server, let it stay there and use "whatever" for the client(s). A bit of web, a bit of native, it all helps.

Volguus
Mar 3, 2009

Bognar posted:

The point is, be judicious in how you apply DI.

Be judicious how you design and write code. Never make blanket rules (such as "all classes have an interface") unless you know you're working with people that require them, never say "never do X" unless it's followed by "unless", do use common sense and best practices to solve the problem at hand.

Volguus
Mar 3, 2009

TooMuchAbstraction posted:

Don't forget the platforms being historically garbage. Needing, effectively, three different versions of your website, or just flat-out saying "this website is not compatible with $browser", used to be super-common. Hell, it may still be common in some limited capacity, but not to the scale I remember it being like back in the mid-2000s.

Now, instead of Netscape or IE is Chrome. There are way too many websites out there that only work on chrome, using some non-standard feature of the browser. It's back to where we started, just different actors.

Volguus
Mar 3, 2009

Amazing indeed. But now, to learn tensorflow just to be able to properly solve fizzbuzz seems a bit much. A solution with 4 interfaces and 8 implementations and 20 unit tests could be a bit more down to earth, don't you think?

Volguus
Mar 3, 2009

ZHamburglar posted:

Should I just post my code from when I was learning Javascript? Or would that be considered gore?

You can post the Javascript code you're writing now. Or would that be considered gore?

Volguus
Mar 3, 2009

RandomBlue posted:

Restarted my dotnet core service ~12 hours ago and checked it this morning:



24GB of memory and all it's basically been doing is handling ~8 connections per minute during that time, give or take. Started at about 30MB. How in the gently caress did this big of a memory leak make it to release?

I don't think they have any QA anymore. You are the tester, enjoy.

Volguus
Mar 3, 2009

Eela6 posted:

The fact that Javascript still doesn't have integers is loving mind-boggling.

The fact that Javascript still exists is loving mind-boggling.

Volguus
Mar 3, 2009

NtotheTC posted:

My life as a developer was infinitely easier when the backend was where the logic went and the front end just handled displaying content. But as a user I've gotta say I much prefer it when a site pre-warns me that a form field is invalid before I send it.

Why can't you have both? Why having in the frontend is that much harder?

Volguus
Mar 3, 2009

nielsm posted:

The actual hard part is keeping validation at both ends in sync, or ideally making a solution to use a single code base for both.

This is one of the arguments in favor of having javascript on the server. Sorry, that's just insane. Is just an object validation. Even if you have 1000 of them, their business rules don't change that often (or shouldn't) to actually be a burden to keep in them sync in different languages/platforms. And like someone pointed out earlier, validation on the client is optional (if it's wrong ... meh, the QA will let you know, not big deal either way). The server is what matters.

Volguus
Mar 3, 2009

eschaton posted:

You use something like a predicate object to specify your validation rules, so that you can generate client-side JS from it on the server, and the code generator can do its best to guarantee the client-side JS and the business logic and the generated SQL all behave the same.

That's one way for sure. It will add an additional "compilation" (transpilation, shittyzation) step, but it would certainly be worth it if it's such a big pain to manually keep them in sync. In my book, this is at most a "meh, whatever" problem.

Volguus
Mar 3, 2009

leper khan posted:

It's nonstandard

True, but pretty much everyone supports it: https://en.wikipedia.org/wiki/Pragma_once . And you can't deny its benefits (over the standard include guards). But now that I think about it, the only time I used #pragma once was when I used Visual Studio and the IDE itself wrote that for me.

Volguus
Mar 3, 2009

Soricidus posted:

I'm the giant block of preprocessor macros to copy/paste into all your header files in order to determine, unreliably, whether or not #pragma once is supported, and if so, to use it completely redundantly in addition to #ifdef guards. This definitely belongs in an encyclopedia

If you even remotely suspect that your code will need to be compilable on compilers written in 3000BC, then using the guards is the right thing to do, no question about it. Is not even worth it otherwise. You deserve my compassion and condolences.

Adbot
ADBOT LOVES YOU

Volguus
Mar 3, 2009

NihilCredo posted:

I don't know either Haskell or Go (but would loving suck it up and learn either if critical to my company).

Go is a trivial language to learn for anyone. Haskell ... let's just say is has a bit steeper learning curve. Not insurmountable, of course, if you put your mind to it, but you need to want to put your mind to it.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply