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
npe
Oct 15, 2004

Pollyanna posted:

Cool. So why not write in another language like Scala, Jython or Clojure and have that run on the JVM instead?

I work for a company that has taken the plunge and is attempting to do as much as possible in Scala, for this reason. I feel somewhat experienced to talk about this.

The main reason most companies stick with plain Java is that it's well understood by a lot of people and there's a zillion native libraries for it. Yes, you can use almost all of these libraries from these other languages, but there are pain points (Scala does not suffer nulls gladly, so you need to be careful when interacting with regular java libs). Scala uses different types, and has tricks for getting around type erasure, all of which you will run into as a problem at some point or another.

It's easier to hire people who know Java - it's been around forever and it's been the lingua franca of ENTERPRISE applications for years. If you need to hire 5 mediocre dudes quickly, Java is easy to find.

But additionally, and more importantly, I would be lying if I said that it's pain-free to write Scala in practice. For one thing, if you have any mediocre programmers on your team they will quickly be lost and do terrible things. But worse, the toolchain support is sketchy at best - so far IntelliJ with the Scala plugin has been ok, but it's nowhere near as mature as native Java support. Compile times are much slower, too.

I love Scala and think we made the right choice, but a more established, conservative company with a larger team will balk at these issues and I can't say I'd blame them.

Adbot
ADBOT LOVES YOU

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Pollyanna posted:

What in god's name is the reason for keeping this crap? Could it somehow not get any more efficient or something? Why does everything have to be a class?! All I want to do is print Hello World, come on.

"Oh god it takes 6 or 7 lines of boilerplate code to print hello world, this is inefficient crap"

I'm not a huge fan of Java, but having to define an entry point is not one of the problems I have.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
From a pedagogical standpoint, "public static void main" is being taught without understanding exactly what's going on. I don't think Java is a great language for learning on.

Freakus
Oct 21, 2000

Ithaqua posted:

"Oh god it takes 6 or 7 lines of boilerplate code to print hello world, this is inefficient crap"
Hey now, Java severely harms the rate at which I can churn out "hello world" apps at my job.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Suspicious Dish posted:

From a pedagogical standpoint, "public static void main" is being taught without understanding exactly what's going on. I don't think Java is a great language for learning on.

It's weird because it's not like a main function is complicated, you can explain each part of why it's signature is like that to computer science students in less than a minute.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Pollyanna posted:

What in god's name is the reason for keeping this crap? Could it somehow not get any more efficient or something? Why does everything have to be a class?! All I want to do is print Hello World, come on.

Also, the interactive tutorial on learnjavaonline.org errors out when you try to complete the exercise. Bodes well for me.

Go pick up Processing. It's Java for artists who don't need to learn how to program, and you're not forced to declare your "hello world" line in ~a class~.

fritz
Jul 26, 2003

Pollyanna posted:

What in god's name is the reason for keeping this crap? Could it somehow not get any more efficient or something? Why does everything have to be a class?! All I want to do is print Hello World, come on.

Why don't you stick with matlab or something then.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

piratepilates posted:

It's weird because it's not like a main function is complicated, you can explain each part of why it's signature is like that to computer science students in less than a minute.

Just because you can blurt an explanation out in under minute doesn't mean fresh undergrads will understand wtf your're saying. This is true if it's not their first programming language, but that's not what Suspicious Dish is talking about.

ephphatha
Dec 18, 2009




This is the thread we talk about lovely code still, right?
code:
begin-procedure get_all_persons
let $proc_name = 'get_all_rooms'
begin-select on-error=bad_select ($proc_name)
people_id,
   add 1 to #pers_counter
   put &people_id into persons(#pers_counter)
from people
where people_id like '%'
and (people_record_chg <> 'N' and
     people_record_chg is null)
order by people_id
end-select
end-procedure
This is being run on an Oracle database so null values fail any equality test, meaning "null <> 'N'" is false. So the nested and clause can never be true and this query returns no results. Plus misleading error reporting and a useless where clause as a cherry.

TheresaJayne
Jul 1, 2011

Pollyanna posted:

What in god's name is the reason for keeping this crap? Could it somehow not get any more efficient or something? Why does everything have to be a class?! All I want to do is print Hello World, come on.

Also, the interactive tutorial on learnjavaonline.org errors out when you try to complete the exercise. Bodes well for me.

Errm,

Have you ever tried a J2EE application, you dont have a main method there? or for an applet, all our servlets have @RequestMapping annotations and no sign of a main.

Main is used when you are running an application command line or GUi and its that way so you know where the program starts, otherwise it could start running anywhere...

Pascal now that was a strict language, you put the start of the program at the bottom and all subroutines if they called another had to be below the one they called.

NtotheTC
Dec 31, 2007


Pollyanna posted:

What in god's name is the reason for keeping this crap?

Come now, you have python background. How is:

Python code:
if __name__ == "__main__":
    # code 
In any way less obtuse for a new programmer.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Although this is entertainingly dated, I'm not clear on why it counts as a coding horror...

shrughes
Oct 11, 2008

(call/cc call/cc)

https://www.youtube.com/watch?v=rRbY3TMUcgQ

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

NtotheTC posted:

Come now, you have python background. How is:

Python code:
if __name__ == "__main__":
    # code 
In any way less obtuse for a new programmer.

It's not mandatory, you only have to do that if you're doing weird stuff, like having a python script be both a library and the application executable. I prefer keeping those two concepts separate and as a consequence, never have to do it.

NtotheTC
Dec 31, 2007


Edison was a dick posted:

It's not mandatory, you only have to do that if you're doing weird stuff, like having a python script be both a library and the application executable. I prefer keeping those two concepts separate and as a consequence, never have to do it.

Maybe you don't, but it's prolific enough that it's shoved down the throats of most new python programmers at some stage, and isn't intuitive enough to prevent them having to go and specifically look up (or be told) what it does. Which is why it was odd to me that a python programmer would take exception to public static void main as being too hard to grasp and a reason why Java was a poor language for newcomers.

Pollyanna
Mar 5, 2005

Milk's on them.


Ephphatha posted:

This is the thread we talk about lovely code still, right?

Yup



edit: I should still prolly bite the bullet and learn java anyway.

Pollyanna fucked around with this message at 15:51 on Oct 4, 2013

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

What's lovely about that? (other than the fields being public, which kinda defeats the purpose of having get/set methods)

That's exactly how you're supposed to implement that in Java. And not to turn into a broken record espousing the superiority of .NET, but in C#, you can express the same thing with public int Foo {get; set;}

You're not supposed to expose public fields. The reason is that the fields represent the internal state of your object. Letting anything go and mess with those willy-nilly is going to cause you problems down the line when you change your implementation. By giving a set of methods that allow you to retrieve/mutate the internal state of the object, you can change the internal implementation without introducing a breaking change in your code.

NtotheTC
Dec 31, 2007


It took me a moment to realise the first method wasn't actually ejactulate()

Posting Principle
Dec 10, 2011

by Ralp
Following the JavaBean standard isn't a horror. I've got some immutable beans in my current project, and just by following the standard they're able to be serialized by Jackson and JAXB automagically. It's awesome.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

I think the horror was referring to the not implemented setters

Workaday Wizard
Oct 23, 2009

by Pragmatica

Who is the girl?

E: I mean the nosering hipster


Never mind found it.

I was hoping it was an embarrassing Ruby webdev hipster stereotype, it wasn't.

Workaday Wizard fucked around with this message at 16:15 on Oct 4, 2013

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Also if the horror is supposed to be the crushing verbosity of writing all that you can:
  • Use mutable public fields with the understanding that it may bite you later in various ways
  • Write an immutable class that makes public fields final, which is less dangerous but still might limit your ability to refactor later
  • Let your IDE write accessors and mutators automatically for you

nielsm
Jun 1, 2009



carry on then posted:

I think the horror was referring to the not implemented setters

You mean setEntityContext method? I don't think that's supposed to be just a simple setter, but something related to the EJB framework stuff. (Is there a concise explanation of what EJB classes actually involve anywhere?)

Pollyanna
Mar 5, 2005

Milk's on them.


I guess if IDEs and such auto-write the private main int void immut { private main function { printf( 2 + 3) } } stuff for me it's not so bad. Still annoying to read, though. Maybe I'm too used to scripting languages.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Ithaqua posted:

You're not supposed to expose public fields. The reason is that the fields represent the internal state of your object. Letting anything go and mess with those willy-nilly is going to cause you problems down the line when you change your implementation. By giving a set of methods that allow you to retrieve/mutate the internal state of the object, you can change the internal implementation without introducing a breaking change in your code.

I really don't understand this. It's the ultimate "let's plan for all software changes".

This has saved me exactly one time, where I flipped a boolean notBroken; around to boolean broken; and was able to leave some basic compatibility getter/setters that I immediately deprecated, and then eventually removed, because people kept on using them wrong.

Chances are that when you change the internals of an object, the API also changes, even if subtly.

It really doesn't help that the language doesn't help you do this best practice, by having public fields as a built-in feature, but not getters/setters. If you need to go out of your way to apply a best practice, the language's design is lovely.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Suspicious Dish posted:

I really don't understand this. It's the ultimate "let's plan for all software changes".

This has saved me exactly one time, where I flipped a boolean notBroken; around to boolean broken; and was able to leave some basic compatibility getter/setters that I immediately deprecated, and then eventually removed, because people kept on using them wrong.

Chances are that when you change the internals of an object, the API also changes, even if subtly.

It really doesn't help that the language doesn't help you do this best practice, by having public fields as a built-in feature, but not getters/setters. If you need to go out of your way to apply a best practice, the language's design is lovely.

That's why .NET has had auto-implemented properties since 2005. It's a good practice, and it shouldn't be cumbersome to implement. At least in the .NET world, the recommendation is to only use private fields and public properties is also because changing a field to a property is a breaking change; any assembly dependent on the changed assembly would also have to be recompiled.

MrMoo
Sep 14, 2000

NtotheTC posted:

It took me a moment to realise the first method wasn't actually ejactulate()

There's certainly an English horror there, ejbPassivate().

pigdog
Apr 23, 2004

by Smythe

Suspicious Dish posted:

Chances are that when you change the internals of an object, the API also changes, even if subtly.
That's... not necessarily supposed to happen.

Generating setters/getters is a couple of keystrokes in an IDE, but by all means you can use public fields too.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I suspect that the valid argument for getters and setters is valid in the same way that the argument for the extra verbosity in a statically-typed langauge not being an important time sink.

In other words, if they irritate you, don't use them with the understanding that in some sort of environments it will bite you in the rear end. There's probably vast swaths of programming environments where the irritant of having to deal with them is not out weighed by API changes breaking stuff.

In other other words, use them if you need to, but understand that there's plenty of people who don't need to (and vice versa).

ManoliIsFat
Oct 4, 2002

Suspicious Dish posted:

From a pedagogical standpoint, "public static void main" is being taught without understanding exactly what's going on. I don't think Java is a great language for learning on.

I think this is crazy. Who doesn't remember glossing over the finer points of streams in c++ their first "cout << "hello world!"? You're still at the ground floor of learning this poo poo in the situation that'd be confusing or offputing. I think this idea that people have to understand everything down to the assembly and the physics of transistors is crazy (obviously being hyperbolic). You don't start kids out with number theory and formal logic, you start um with addition and subtraction. Sure, it may be "simpler" to teach someone a bash script or python where it just starts on the first line, read through the script like a document, but I really don't think just glossing over "hey, programs gotta start somewhere" is that detrimental to the pedagogy.

If you're teaching someone who will NEVER try to program something again in their life, maybe. But I really don't see how they're gonna be confused or misled by "just accept for these first couple of weeks that 'public static void main' is a magical incantation"

b0lt
Apr 29, 2005

ManoliIsFat posted:

I think this is crazy. Who doesn't remember glossing over the finer points of streams in c++ their first "cout << "hello world!"? You're still at the ground floor of learning this poo poo in the situation that'd be confusing or offputing. I think this idea that people have to understand everything down to the assembly and the physics of transistors is crazy (obviously being hyperbolic). You don't start kids out with number theory and formal logic, you start um with addition and subtraction. Sure, it may be "simpler" to teach someone a bash script or python where it just starts on the first line, read through the script like a document, but I really don't think just glossing over "hey, programs gotta start somewhere" is that detrimental to the pedagogy.

If you're teaching someone who will NEVER try to program something again in their life, maybe. But I really don't see how they're gonna be confused or misled by "just accept for these first couple of weeks that 'public static void main' is a magical incantation"

On the other hand, streams are insane and terrible.

UraniumAnchor
May 21, 2006

Not a walrus.
code:
	[XmlElement("objectIds")]
	public string objectIds = string.Empty;		// this only needs to be public so it gets serialized. 
										// it shouldn't be directly modified by other classes. use the accessor functions
	
	public void AddObjectId(string addObject) {
		if(!objectIds.Contains(addObject)) {
			List<string> allObjectIds = new List<string>(objectIds.Split(' '));
			allObjectIds.Add(addObject);
			objectIds = "";
			for(int i = 0; i < allObjectIds.Count; i++) {
				objectIds += allObjectIds[i];
				if(i < allObjectIds.Count - 1) {		// avoid leaving a trailing space
					objectIds += " ";
				}
			}
		}
	}
	
	public void RemoveObjectId(string removeObject) {
		List<string> allObjectIds = new List<string>(objectIds.Split(' '));
		objectIds = "";
		for(int i = 0; i < allObjectIds.Count; i++) {
			if(allObjectIds[i] == removeObject) {
				continue;		// rebuild the string minus this name
			}
			
			objectIds += allObjectIds[i];
			if(i < allObjectIds.Count - 1) {		// avoid leaving a trailing space
				objectIds += " ";
			}
		}
	}
	
	public bool HasObjectId(string checkName) {
		return objectIds.Contains(checkName);
	}
:staredog:

I replaced this entire mess with a HashSet...

Freakus
Oct 21, 2000
We've had some changes in the past we decided not to do because we didn't use getters and setters. The hilarious part was at some point when our codebase was a fraction of its current size someone actually REMOVED them.

nielsm
Jun 1, 2009



Freakus posted:

We've had some changes in the past we decided not to do because we didn't use getters and setters. The hilarious part was at some point when our codebase was a fraction of its current size someone actually REMOVED them.

This. Having controlled access to public data on objects seems like a bad tax when your project is small, but at some point you will end up hating yourself for not having done it.
You might need to virtualize a field to be a calculation of something else, or fire off an event when something changes, or validate inputs, or a million other things. (And keep in mind that prototype systems tend to be promoted to production.)

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

nielsm posted:

(And keep in mind that prototype systems tend to be promoted to production.)
This is a horror I had to face. Our prototype system was in limited testing to see if the idea would work in the real world rather than in theory and only supposed to be used by a subset of users. Over the weekend the business owner's director launched all of their areas and users without asking then said we couldn't take it offline because it was "business critical".

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

nielsm posted:

(And keep in mind that prototype systems tend to will inevitably be promoted to production.)

ManoliIsFat posted:

If you're teaching someone who will NEVER try to program something again in their life, maybe. But I really don't see how they're gonna be confused or misled by "just accept for these first couple of weeks that 'public static void main' is a magical incantation"

I'm coming around to the view that starting with OOP right out of the gate is a bad way to teach introductory programming. Seems more straightforward to introduce "data" and "operations on data" before jumping right into why you would want to combine the two for ~*abstraction*~.

nielsm
Jun 1, 2009



Monkeyseesaw posted:

I'm coming around to the view that starting with OOP right out of the gate is a bad way to teach introductory programming. Seems more straightforward to introduce "data" and "operations on data" before jumping right into why you would want to combine the two for ~*abstraction*~.

That's exactly the same thing I experienced when I took a (rather low level) CS education to get some papers on my skills. It was Java all the way, and everyone was struggling with why you would even want objects. One actually came up with the idea "can't you just store everything in ArrayLists?" since those were easy data structures to understand. Yeah, you can and you're basically doing what programmers were doing 40 years ago then, but Java really also gets in your way when doing that.
It's hard to understand how you design a good class, so you really need to have spent a lot of time working with simpler (to understand) data structures first.

ManoliIsFat
Oct 4, 2002

Monkeyseesaw posted:

I'm coming around to the view that starting with OOP right out of the gate is a bad way to teach introductory programming. Seems more straightforward to introduce "data" and "operations on data" before jumping right into why you would want to combine the two for ~*abstraction*~.
You know I was thinking about this a bunch over lunch, and I totally feel you. It's probably a case of "I learned it that way, and I came out fine!". But if I really think about it, I started in QBasic, and ignored objects in c++ until I was more experienced. You're totally right that a really feeling comfortable with manipulating data and basic control flow probably is a big enough mental hurdle for a novice, and really any discussion of OOP (or even organization/pattern in general) is really gonna just be putting the cart before the horse.

hazzlebarth
May 13, 2013

Taken from http://localhost.re/p/whmcs-527-vulnerability :

code:
<?php
function update_query($table, $array, $where) {
    #[...]
    if (substr($value, 0, 11) == 'AES_ENCRYPT') {
        $query .= $value.',';
        continue;
    }
    #[...]
    $result = mysql_query($query, $whmcsmysql);
 }
?>
I know, due to the easiness of getting into php programming there is a lot of really lovely code out there, but drat, that's gotta be up at the top of the pile of bad ideas.

Adbot
ADBOT LOVES YOU

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

hazzlebarth posted:

Taken from http://localhost.re/p/whmcs-527-vulnerability :

code:
<?php
function update_query($table, $array, $where) {
    #[...]
    if (substr($value, 0, 11) == 'AES_ENCRYPT') {
        $query .= $value.',';
        continue;
    }
    #[...]
    $result = mysql_query($query, $whmcsmysql);
 }
?>
I know, due to the easiness of getting into php programming there is a lot of really lovely code out there, but drat, that's gotta be up at the top of the pile of bad ideas.

When I was running a web host last yearish, WHMCS screwed me over pretty badly by allowing an attacker access to the loving root of the system (it needs the WHM information to be able to create accounts. WHM uses root details.) loving pain in the rear end. Really though it's a great system; it's too bad it's PHP.

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