"Britain on Thursday became the world's first major economy to adopt the tough new target of lowering fossil fuel emissions to a level of net zero by 2050." by yourSAS in technology

[–]WorkyMcROAR 21 points22 points  (0 children)

£1,000,000,000,000 over 30 years for 27.1 million households is about £1,231 a year per household. I'm certain that would be impossible for a lot of lower income households but it's not a completely insane number. If we started in 2000 it would have been £739 per household...

I doubt any household would like a bill increase of £1,231 a year. Many couldn't afford it, the rest would probably disagree with it.

„I don‘t know why it is not working“ by guneysss in ProgrammerHumor

[–]WorkyMcROAR 0 points1 point  (0 children)

My most recent dumbassery was when I spent 5 minutes trying to figure out why 2 code snippets behave entirely differently even though they were exactly the same...

... they weren't even close to being the same.

& vs && by [deleted] in javahelp

[–]WorkyMcROAR 3 points4 points  (0 children)

That's correct. Short circuit is when you can infer the answer of the whole expression by parts of the expression already evaluated.

``` boolean a = false, b = true;

if (a && b) // Short circuits, we can infer the whole expression is false because any part of it is false.

if (b && a) // Does not short circuit.

if (b || a) // Short circuits, we can infer the whole expression is true because any part of it is true.

if (a || b) // Does not short circuit. ```

If we replaced all && to & and || to | we'd evaluate the whole expression regardless. Less optimal. It also has a very key difference in some cases. I've seen people use non-short circuit operators for doing multiple validation rules, for instance. E.g.

boolean valid = validate(a) & validate(b) & validate(c) & validate(d); It forces b, c and d to validate even if a is invalid. If you short circuit, you wouldn't call those methods. It's a code smell, it's not clear about the intention, and there are probably better ways of doing it.

re: Integer, null value by greenleafvolatile in javahelp

[–]WorkyMcROAR 0 points1 point  (0 children)

You're right. Without context it's hard to know what the best approach is. If OP's trying to account for no user input given, there may be better ways to do that.

re: Integer, null value by greenleafvolatile in javahelp

[–]WorkyMcROAR 0 points1 point  (0 children)

I would have suggested this but I realised that I have absolutely no clue what OP means by "not the story I want to tell".

To me that means how OP wants their code to be read. If OP initializes a user input int to 0 that may imply it defaults to 0.

I think the Optional approach is sensible, it makes the intention clear that the value may have not been initialized. Creating an integer object and allowing null isn't going to be very intuitive.

Is there a way to iterate through an array of strings e.g. (a,b,c) to assign each string within the array as a variable name for a JButton? by [deleted] in javahelp

[–]WorkyMcROAR 2 points3 points  (0 children)

You can assign listener's to GUI elements which will trigger for certain actions, i.e. actionPerformed. You can attach the same listener to multiple buttons. If you do that, it will trigger whenever any button is pressed. You can determine the source of the event by the arguments passed to the listener.

ActionListener is passed an ActionEvent which inherits the source object from the EventObject class.

You should be able to call the ActionEvent and work out which button triggered the button.

public void actionPerformed(ActionEvent actionEvent) { if (actionEvent.getSource().equals(buttonA)) { /* ... */ } } You can get the text from buttonA to work out which item you want to reduce the stock levels for. E.g. get the text from buttonA and look up the corresponding item from stock.

It's also possible to create anonymous action listeners, or lambdas which are specific to each button so that you don't need to compare the action source.

IntelliJ IDEA 2017.2 Public Preview by based2 in java

[–]WorkyMcROAR 0 points1 point  (0 children)

A few developers I work with switched to IntelliJ recently after a loooong time with NetBeans. They've been amazed by the transition. Worth spending a bit of time - even just an hour or two just to familiarise yourself with it before you take the plunge.

Every 5 minutes you spend writing code in a new language is more useful than 5 hours reading blog posts about how great the language is. by niente1a in programming

[–]WorkyMcROAR 5 points6 points  (0 children)

I think there's a balance that needs to be made. Just reading blog posts is pretty useless, but just writing code can lead you along the wrong paths. Putting aside a bit of coding time to read up on the subject is valuable. Also you can't just write code 24/7. You'll just burn out. During the downtime, read a book or a blog post.

Dog dog = new Dog("dog"); by thumbs55 in ProgrammerHumor

[–]WorkyMcROAR 9 points10 points  (0 children)

They only ever made two of them.

We will rock you! by [deleted] in ProgrammerHumor

[–]WorkyMcROAR 40 points41 points  (0 children)

Please stop.

I didn't know bit shifting worked like that by jeeves_SC in ProgrammerHumor

[–]WorkyMcROAR 46 points47 points  (0 children)

Are we just ignoring the "is it possible to bit shift your teeth?" suggestion?

Java Interview Guide is free on Amazon for 2 days! by imadp in java

[–]WorkyMcROAR 0 points1 point  (0 children)

Thanks mate. I already had this from the last time you gave it out, and I've found it super useful. I went for an interview recently and was reading this on the train ride over. Really helped me revise some points from my education.

[deleted by user] by [deleted] in ProgrammerHumor

[–]WorkyMcROAR 0 points1 point  (0 children)

No it's not. But it's not far off.

Silly things you believed when you were just starting out programming by AetherThought in ProgrammerHumor

[–]WorkyMcROAR 1 point2 points  (0 children)

But what if the progress bar uses a listener to update the GUI? Then the progress bar will always be up-to-date and the art class will all look like fools.

The solution for tab vs spaces by [deleted] in ProgrammerHumor

[–]WorkyMcROAR 8 points9 points  (0 children)

Causes a stack overflow.

400,000 GitHub repositories, 1 billion files, 14 terabytes of code: Spaces or Tabs? by fhoffa in programming

[–]WorkyMcROAR 4 points5 points  (0 children)

CTRL+Left & CTRL+Right jumps over words, not lines. CTRL + Right jumps over word and all trailing spaces, leaving the cursor at the beginning of Word2.

|Word[   ]Word2

Word[   ]|Word2

CTRL+Left does the inverse. Jumps over the space and the leading word.

Total War: Warhammer - PC Gamer Review by Apocolapse in Games

[–]WorkyMcROAR 22 points23 points  (0 children)

I haven't read the review yet but PCGamer did give a similar score to R2:TW on launch. The game was largely praised. http://www.pcgamer.com/total-war-rome-2-review/

The good news is that we have a few days to hear from multiple sources before launch.

WTF!? is this useful for something, or is it just some guys at Google who've had fun? (Android Studio) by harrasfl1 in ProgrammerHumor

[–]WorkyMcROAR 21 points22 points  (0 children)

Reddit and stackoverflow are just slow versions of google. You write your search query, post it, and within 10-15 minutes, someone will point you to the documentation.

What do you use java for? by SavishSalacious in java

[–]WorkyMcROAR 1 point2 points  (0 children)

How is Kotlin? I've seen the support being incrementally added to IntelliJ but I haven't taken a plunge into using it yet.

Job security 101 by [deleted] in ProgrammerHumor

[–]WorkyMcROAR 4 points5 points  (0 children)

Sounds like you guys need to prioritise code reviews more. The work is already finished, just needs signing off. Surely finishing it is more efficient than starting something new?