Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

What the fuck is this shit?

Name: Anonymous 2005-11-16 13:31

was my first reaction upon looking at Azureus's source code. To think I actually use this...

Name: Anonymous 2005-11-16 19:37

Could you elaborate? I'm not a coder, but I'm interested in discussions of languages and coding styles.

Name: Anonymous 2005-11-16 21:07

>>2
Ah, a typical /prog/tard then.

>>1
But yeah, show us some specific code that makes you barf. Don't forget the [code] tag.

Name: Anonymous 2005-11-17 4:14

lol java

Name: Anonymous 2005-11-17 6:01

A specific example? How about I pick any random file, I'm sure I'll find something that pisses me off. Let's see here, I'll start by digging down through the retarded module organization required by the java guidelines. org/bouncycastle/util/encoders/

Ok, we're here. Hex.java, and HexTranslator.java. One might wonder exactly where they are used, but a quick grep suggests that they are not in fact used anywhere. They're just littering the source, probably because deleting things from CVS is a pain; or so I think, it's been a while since I used cranky old CVS.

Picking on code that isn't used anymore might be unfair, but it's still there, hurting my eyes.

Name: Anonymous 2005-11-17 6:03

package org.bouncycastle.util.encoders;

/**
 * Converters for going from hex to binary and back. Note: this class assumes ASCII processing.
 */
public class HexTranslator
    implements Translator
{
    private static final byte[]   hexTable =
        {
            (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7',
            (byte)'8', (byte)'9', (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f'
        };

    /**
     * size of the output block on encoding produced by getDecodedBlockSize()
     * bytes.
     */
    public int getEncodedBlockSize()
    {
        return 2;
    }

    public int encode(
        byte[]  in,
        int     inOff,
        int     length,
        byte[]  out,
        int     outOff)
    {
        for (int i = 0, j = 0; i < length; i++, j += 2)
        {
            out[outOff + j] = hexTable[(in[inOff] >> 4) & 0x0f];
            out[outOff + j + 1] = hexTable[in[inOff] & 0x0f];

            inOff++;
        }

        return length * 2;
    }

    /**
     * size of the output block on decoding produced by getEncodedBlockSize()
     * bytes.
     */
    public int getDecodedBlockSize()
    {
        return 1;
    }

    public int decode(
        byte[]  in,
        int     inOff,
        int     length,
        byte[]  out,
        int     outOff)
    {
        int halfLength = length / 2;
        byte left, right;
        for (int i = 0; i < halfLength; i++)
        {
            left  = in[inOff + i * 2];
            right = in[inOff + i * 2 + 1];
           
            if (left < (byte)'a')
            {
                out[outOff] = (byte)((left - '0') << 4);
            }
            else
            {
                out[outOff] = (byte)((left - 'a' + 10) << 4);
            }
            if (right < (byte)'a')
            {
                out[outOff] += (byte)(right - '0');
            }
            else
            {
                out[outOff] += (byte)(right - 'a' + 10);
            }

            outOff++;
        }

        return halfLength;
    }
}

Name: Anonymous 2005-11-17 6:05

package org.bouncycastle.util.encoders;

/**
 * Converters for going from hex to binary and back.
 * <p>
 * Note: this class assumes ASCII processing.
 */
public class Hex
{
    private static HexTranslator   encoder = new HexTranslator();

    private static final byte[]   hexTable =
        {
            (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7',
            (byte)'8', (byte)'9', (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f'
        };

    public static byte[] encode(
        byte[]  array)
    {
        return encode(array, 0, array.length);
    }

    public static byte[] encode(
        byte[]  array,
        int     off,
        int     length)
    {
        byte[]      enc = new byte[length * 2];

        encoder.encode(array, off, length, enc, 0);

        return enc;
    }

    public static byte[] decode(
        String  string)
    {
        byte[]          bytes = new byte[string.length() / 2];
        String          buf = string.toLowerCase();
       
        for (int i = 0; i < buf.length(); i += 2)
        {
            char    left  = buf.charAt(i);
            char    right = buf.charAt(i+1);
            int     index = i / 2;
           
            if (left < 'a')
            {
                bytes[index] = (byte)((left - '0') << 4);
            }
            else
            {
                bytes[index] = (byte)((left - 'a' + 10) << 4);
            }
            if (right < 'a')
            {
                bytes[index] += (byte)(right - '0');
            }
            else
            {
                bytes[index] += (byte)(right - 'a' + 10);
            }
        }

        return bytes;
    }

    public static byte[] decode(
        byte[]  array)
    {
        byte[]          bytes = new byte[array.length / 2];

        encoder.decode(array, 0, array.length, bytes, 0);

        return bytes;
    }
}

Name: Anonymous 2005-11-18 11:10

Today, let's look at something that is actually used. Probably.
  public void
  stopIt(
      final int             _stateAfterStopping,
    final boolean         remove_torrent,
    final boolean         remove_data )
  {
    if( state == DownloadManager.STATE_STOPPED ||
        state == DownloadManager.STATE_ERROR ) {

            //already in stopped state, just do removals if necessary

      if( remove_data )  deleteDataFiles();

      if( remove_torrent )  deleteTorrentFile();

      setState( _stateAfterStopping );

      return;
    }


    if (state == DownloadManager.STATE_STOPPING){

        return;
    }

      setState( DownloadManager.STATE_STOPPING );

          // this will run synchronously but on a non-daemon thread so that it will under
          // normal circumstances complete, even if we're closing

      try{
          NonDaemonTaskRunner.run(
            new NonDaemonTask()
            {
                public Object
                run()
                {
                    int    stateAfterStopping = _stateAfterStopping;

                    try{

                        if (peerManager != null){
                          stats.setSavedDownloadedUploaded(
                                  stats.getSavedDownloaded() + peerManager.getStats().getTotalDataBytesReceived(),
                                   stats.getSavedUploaded() + peerManager.getStats().getTotalDataBytesSent());

                          stats.saveDiscarded(stats.getDiscarded());
                          stats.saveHashFails(stats.getHashFails());
                          stats.setSecondsDownloading(stats.getSecondsDownloading());
                          stats.setSecondsOnlySeeding(stats.getSecondsOnlySeeding());

                          peerManager.removeListener( peer_manager_listener );

                          peerManager.stopAll();

                          try{
                              peer_listeners_mon.enter();

                              peer_listeners.dispatch( LDT_PE_PM_REMOVED, peerManager );

                          }finally{

                              peer_listeners_mon.exit();
                          }

                          peerManager = null;
                        }

                            // kill the tracker client after the peer manager so that the
                            // peer manager's "stopped" event has a chance to get through

                        if ( tracker_client != null ){

                            tracker_client.removeListener( tracker_client_listener );

                            download_manager_state.setTrackerResponseCache(
                                        tracker_client.getTrackerResponseCache());

                            tracker_client.destroy();

                            tracker_client = null;
                        }

Name: Anonymous 2005-11-18 11:20

* The function is so fucking large that I'm not allowed to paste it whole. That's rarely a good thing.

* It suffers from a mixture of both tabs and spaces for indentation (which won't be obvious when posted here) Please, just pick one or the other.

* What the fuck, seven levels of indentation?!

* Excessive use of newlines

* It's inconsistent. "if( blah )" or "if (blah)", pick one style, preferably the latter.

There ARE automated tools for beautifying code, you know.

Name: Anonymous 2005-11-18 11:48

>>9
so you're annoyed that the code *looks* bad? at least critisize the actual code instead of bitching about how it looks.

Name: Anonymous 2005-11-18 15:24

Seven levels of indentation and overly-long functions are a sign of poor code.

Also, if they can't be assed to use a beautifier, that's not a good sign either.

Name: Anonymous 2005-11-18 15:37

>>10
If code looks bad, it probably is bad. Sorta like when people post a single huge paragraph on a forum with no punctuation or capitalisation - it doesn't affect the content, but even so, what are the chances that the content will actually be worth reading? A programmer who doesn't care about how his code looks probably doesn't care about how his code works.

Name: Anonymous 2005-11-19 0:24

>>12
or maybe not. who cares how the program looks like. what is important is what it does. critisizing the looks is so immature and useless because one can just use a code beautifier to better it a second. the actual code is what matters and the only thing that should be open to critisization.

Name: Anonymous 2005-11-19 3:30

That's the point, >>13. They could have, but they didn't. Not a good indicator.

And again, seven levels of indentation, or really long functions, has nothing to do with the beautifiers. They're a really bad sign the code wasn't thought out.

Name: Anonymous 2005-11-19 8:34

if code /looks/ bad, it's harder to read.  if code is harder to read, it's easier for bugs to slip in, and harder for programmers to catch them.  this generally results in a low quality application.

this is especially the case if more than one programmer is working on the same project.

as an end-user, if i try to view a program's source code and it's hard to read, it's not good.  i have little to no idea what it's actually doing on my system, or what it's supposed to do.  makes me less likely to ever use this program again.

bad style == bad program.

Name: Anonymous 2005-11-19 9:01

I agree with you >>15, but the third paragraph is pure BS. Nobody except an ubergeek gives a shit that they can view the source code (and 99% of ubergeeks who rant about open source never look at the source anyway).

Just say that ugly code == baddy bad, and leave it at that.

Name: Anonymous 2005-11-19 11:42 (sage)

>>15
ok you're welcome to not use azureus.... for the rest of us, it works just fine thank you

Name: Anonymous 2005-11-19 12:23 (sage)

>>17
i don't think >>1 was necessarily eluding to hating Azureus, but that it amazed (or perhaps stupified) him/her to find such poorly written code in a large, functional (, Open Source?) program such as that.  maybe it was their first time seeing something like that!  ;-)  i've seen worse code.  live and learn

Name: Anonymous 2005-11-19 14:11 (sage)

>>18
or alluding even . . . doh

Name: Anonymous 2005-11-19 14:29

>>17
"It works just fine" is the call of the ignorant. This is /Programming/, go back to /Computers/ if you don't like it here.

>>18
I've seen some bad code in my days, hell, I've written my share of it, and I know many programs are a patchwork of hacks barely held together. But I'm still inclined to bitch when I see something I don't like. Especially when it's in a big and popular program.

Name: Anonymous 2005-11-19 19:03

>>20
I like it just fine here, thank you.

IMHO, you shouldn't even be looking at the code on a line-by-line level to get the general feel of it. Look at the object hierarchy, flow of execution, threads, events, how the objects interact - these are all things that matter and determine the understandability of the code.

The number of indentation levels in a function is completely irrelevant - maybe the author didn't see a point in moving out the inner code to a different function just because of the indentation, and if there was no need to do it, I don't see why it should matter, other than for "omg ugly hurrr" cosmetic reasons. And yes, this code is very clean compared to some of the shit out there.

Name: Anonymous 2005-11-19 19:55

>>6
That class is fine, aside from the fact the kind of things you're doing there scream "Write me in C! Cock goes in there! I go in C!". Azuerus loses for being written in Java.

>>9
There are some bad things there, but c'mon, is this the worse you saw? You don't work on maintenance, do you? That's not too sucky even for Java (although it does have some suckage, hi peerManager.getStats().getTotalDataBytesReceived()). It could be much worse, believe me. Given the shit I've had to fix, I consider those bits of code fairly acceptable.

Name: Anonymous 2005-11-20 4:40

it has a method named "stopIt". Not just "stop" or "stopDownload" or "stopTorrent", it's "stopIt". WTF

Name: Anonymous 2005-11-21 19:57

>>6
i bet they turned that byte array into a string later

Name: Anonymous 2005-11-21 23:15

public static void stopInternet() throws HowDoIShotWebException

Name: Anonymous 2005-11-22 6:46

>>25
We have a winner

Name: Anonymous 2005-11-23 16:35

>>12
Hear hear. I've long held the rule of thumb that if a programmer can't spell his native language, i.e. english in most cases, properly then how the fuck is he supposed to be able to write proper code? Let alone think clearly?

Case in point, the Enlightenment window manager. The programmer can't spel wort siht. Incidentally, the whole project has been through what, 7 complete rewrites since 1998?

Name: Anonymous 2005-11-23 16:36

>>12
Hear hear. I've long held the rule of thumb that if a programmer can't spell his native language, i.e. english in most cases, properly then how the fuck is he supposed to be able to write proper code? Let alone think clearly?

Case in point, the Enlightenment window manager. The programmer can't spel wort siht. Incidentally, the whole project has been through what, 7 complete rewrites since 1998?

Name: Anonymous 2005-11-23 17:51

I was quite surprised at how bad Rasterman writes English. It's AOL-grade.

But there's little doubt he can code.

Name: Anonymous 2005-11-23 18:43

>>27
WTF "in most cases". Get your head out of your native English-speaking ass.

Name: Anonymous 2005-11-26 22:33

>>30
My native language isn't english. It's just that english is the lingua franca of programming, therefore "i.e. english in most cases". No offense intended. Still, it's no surprise that most of us for whom english is a second or third language spell better than the average US american.

>>29
He's certainly good at turning out piles and piles of code that begs to get replaced. (Un?)fortunately the world moved on and turn-of-the-century baroque visual glitz went out of fashion. The last I took a look at Enlightenment, Rasterman was advocating turning it into a whole separate desktop environment with its own nvidia-specific hardware accelerated windowing system and all... which didn't strike me as at all odd considering the man's record.

Name: Anonymous 2009-01-14 5:01

Use utorrent or on lunix transmission
Azureus is bloatware

Don't change these.
Name: Email:
Entire Thread Thread List