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
Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

TRex EaterofCars posted:

Sun's javac is probably one of the best compilers on earth.

I have no idea what you're talking about. It produces pretty much a direct translation from Java to bytecode with no optimization or anything. It's easy to be the "best" in a nearly completely trivial process.

EDIT: I just realized I skipped a page in my rush to yell at Java, oh well.

Adbot
ADBOT LOVES YOU

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

rjmccall posted:

When javac's hands aren't tied by inter-class abstraction boundaries, it can actually do quite a lot; but of course that's a huge limitation.

You might mean it could do. It doesn't actually do poo poo.

This
code:
int sum( int[] b )
{
  int l = 0;
  for ( int i = 0; i < b.length; ++i ) l += b[ i ];
  return l;
}
and this
code:
int sum( int[] b )
{
  int l = 0;
  int size = b.length;
  for ( int i = 0; i < size; ++i ) l += b[ i ];
  return l;
}
produce different code. If you're using an interpreter to execute this, the performance difference can be huge. There's no reason javac couldn't do the optimization itself; someone just decided that JIT is so awesome, no one's going to ever interpret Java anywhere again.

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

tef posted:

What if b[] is being modified in a different thread?

Then the results are undefined, because Java's volatile is only usable as a field attribute? And also, the length of an array will never change, so this question is pointless? Perhaps I have owned you goon sire?

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

Vanadium posted:

welp, you can in C++ using gcj's java interface.

GCJ Can't Java

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
Yesterday, I was asked "do you know why this crashes?" based on an "application has done terrible things and must die" dialog. I looked at the source, and it looked like this:
code:
int main( void )
{
  #include "initstuff.h"
  //#include "dostuff1.h"
  //#include "dostuff2.h"
  //#include "dostuff3.h"
  #include "dostuff4.h"
  //#include "dostuff5.h"
  //you get the idea, repeat about 50 commented dostuffxx.hs
  #include "shutdown.h"
}
I pressed "debug" and noticed that the main function overflowed the stack. Turns out, the dostuffxy.h that was not commented allocated some enormous arrays on stack. I "fixed" the problem by increasing the initial thread stack reserve size and wept silently.

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

beer_war posted:

code:
bool some_function()
{
 //...

 return boolean_expression ? true : false ;
}
:downs:

I've done that occasionally with cousin int_expression and uncle pointer_expression to make visual c++ shut up. Yeah, there are other ways, such as (bool)int_expression and !!pointer_expression. I don't like them :saddowns:

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

geetee posted:

There is no way &1 even compiles (right?) so I don't understand what this entire fiasco is about. The logical operator "AND" requires two ampersands, not one. I'm surprised none of your IDEs warned you about this. It's just a segfault waiting to happen. Just use modulus and move on.

Hrm good sir I think you are wrong, allow me a moment to write a two-page refutation of this complete with references (with exact page numbers) to the C99 standard, the C++98 standard, the ANSI C standard and the C++0x draft.

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

minato posted:

code:
int i = *(int*)&x;
x = *(float*)&i;

That's pretty likely to go boom on GCC FYI

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

Presto posted:

Should be fine, although it may bitch about violating strict aliasing rules.

It won't "bitch", but it's quite possible that it will randomly fail! Just use unions drat it. Jeet chirst this is making me so angry. What nubbery..

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
I was thinking about plunking this in my code:

code:
template < class T > struct NonPtrWrapper
{
	inline T& operator*() { return t; }
	inline const T& operator*() const { return t; }
	inline T* operator->() { return &t; }
	inline const T* operator->() const { return &t; }
	T t;
};
I think it should qualify.

EDIT: also this
code:
struct IndWrapper
{
	inline unsigned int operator[]( unsigned int n ) const { return n; }
};

Painless fucked around with this message at 15:26 on Feb 6, 2009

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

gibbed posted:

Why is this a horror?

- random, pointless printing to cerr
- creating a T instance makes the byteswap function a lot less generic than it could be
- pointless runtime switching (this will almost certainly get optimized away, though)

among other crimes

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

Lexical Unit posted:

In case y'all were curious, here are the lines of code that lead me to inspect the byteswap header file in the first place,

A horribly wrong way to use a horribly implemented function and simultaneously ignore the existence of a horribly implemented utility function? Nice.

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

quote:

maybe all these problems are gone soon

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
I noticed that clearing a list was taking quite a bit of time so I replaced a list.clear() call with the following line:

code:
new ( &list )std::list< Stuff, MyHackedTogetherAllocator >( list.get_allocator() );
It seems to work I guess and it shaved 20ms from my program's startup time so you know it's worth it

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

Otto Skorzeny posted:

STL lists are Too Slow

Ugggh these people are everywhere and it's never an argument against the design, it's always "I used dinkumware STL 0.1 on Visual C++ 6.0 in a trivial benchmark with a new/delete allocator and it was slower than java! So what the gently caress"

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
The correct way to fix crashes caused off-by-one errors in loops involving arrays is to make every array one element larger than it needs to be
This advice was in Code Complete, so you know it's good

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

geetee posted:

You talked poo poo when you were in no place to have done so and now you're back peddling.

Well CoC is a pretty good place for a back peddler, I think a lot of people here have back problems and would like to buy a new one

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

MononcQc posted:

One of the lead devs back then (years before I got here) was a C programmer down to the bone. Never bothered to get into PHP the way he should have (not that I can blame him).

The proper way to get into PHP is in a casket

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

quote:

CINT is written in C++ itself, with slightly less than 400,000 lines of code.
Holy poo poo that's a lot of code for an interpreter.

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

Lexical Unit posted:


I bet there's a smaller horror inside!

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

king_kilr posted:

Ah java, was my_str == "foobar" really that hard.

Within the constraints of Java's lovely type system, making that the equivalent of "my_str.equals( "foobar" )" would just make problems worse.

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
I dunno, most of that doesn't look that terrible (except for the new(this) part).

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
This is worst derail, occurring on ugliest track

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
That fwrite call is amazing.

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
Also remove exceptions, dynamic_cast and typeid and add restrict from C99, I don't care how much the standard committee :qq:s about how hard it is to define
The language would be almost usable and most C users would have no more excuses
and then remove virtual because class-based polymorphism is an abomination

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
First rule of optimization: assume that your compiler was written in 1983 by an army of white collared chimps with typewriters
Second rule of optimization (follows from first): there's a massive difference between i++ and ++i, especially for primitives
Third rule of optimization: god the neck of this bottle feels amazing in my rear end

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
Yeah so yesterday I saw some punk kid writing "NULL" so I smacked him on the face and was like "yo don't try to be a hero, that pointer's a ZERO"

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

Janin posted:

Just discovered a new take on the for-case pattern (bonus points: spot the bug which brought me to discover this):

That's like a matryoshka of horrors

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
The way you describe it, your way of "fixing" things sounds like a coding horror in itself. Class A has a bug, so fix it by quietly removing 'final' and extending with a class that has the bug fixed?

Adbot
ADBOT LOVES YOU

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

That's a feature of the platform, not the language

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