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
Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

Lone_Strider posted:

"well I'm just making sure"

aka "I can't be bothered to learn something new or correct my gross misunderstanding of something."

Adbot
ADBOT LOVES YOU

Vanadium
Jan 8, 2005

Mustach posted:

You can't subclass java.lang.String.

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

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Sorry, I was talking about Java, not GNU Gava or whatever

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Lone_Strider posted:

Holy poo poo, this is like a tell-tale mark for crappy devs. I bet when he was called on it he said "well I'm just making sure"
I'd say it's something more like "well that's how they did it in the on-line tutorial I more-or-less copied that code snippet from wholesale."

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

Lexical Unit
Sep 16, 2003

My co-worker told me today that const-correctness isn't worth the speed hit.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Painless posted:

GCJ Can't Java

It's getting there:
http://en.wikipedia.org/wiki/Icedtea

HIERARCHY OF WEEDZ
Aug 1, 2005

Vanadium posted:

That just makes the code more portable. In Ruby it is common practice to call .to_s on string-like objects

That's for when you're anticipating receiving either a symbol or a string and want one or the other. It's not just to make sure.

defmacro
Sep 27, 2005
cacio e ping pong
I saw this in some research code recently:
code:
if (integer % 1 == 0) { ... 
Pretty sure it started as something other than 1, but it certainly made me chuckle.

geetee
Feb 2, 2004

>;[

GT_Onizuka posted:

I saw this in some research code recently:
code:
if (integer % 1 == 0) { ... 
Pretty sure it started as something other than 1, but it certainly made me chuckle.

I work with a guy that just changes random poo poo until it appears to work as he intends. Nonsense like this is (unfortunately) a daily occurrence for me :(

ani47
Jul 25, 2007
+

Lexical Unit posted:

My co-worker told me today that const-correctness isn't worth the speed hit.

My co-worker said that having a single 'int i' in the beginning of a function instead of one per for loop saves memory.

Fenderbender
Oct 10, 2003

You have the right to remain silent.

geetee posted:

I work with a guy that just changes random poo poo until it appears to work as he intends. Nonsense like this is (unfortunately) a daily occurrence for me :(

Unfortunately, when someone write codes like that, the only way to get it to work is to rewrite it or jiggle the handle a bit to try and get it to work.

geetee
Feb 2, 2004

>;[
This is what I'm faced with during my continued attempts to stop using a table called "guid" (with 1 row and 1 bigint column) that is locked and incremented upon every insert.

quote:

What they don't mention are all the real-world issues people have run into.

Face it, we're not switching back to auto-increment for any decent size site. Maybe if the framework gave the option we could allow it for small sites. Very very small sites...


Matt

Senior Developer

Matt, if you're a goon, surely you'll understand that I think you're a giant douchebag.

Fenderbender
Oct 10, 2003

You have the right to remain silent.

geetee posted:

This is what I'm faced with during my continued attempts to stop using a table called "guid" (with 1 row and 1 bigint column) that is locked and incremented upon every insert.


Matt, if you're a goon, surely you'll understand that I think you're a giant douchebag.

By any chance do you work in New York?

geetee
Feb 2, 2004

>;[

Fenderbender posted:

By any chance do you work in New York?

If you trust my profile :v:

Arntor
Mar 8, 2005

Hey gnag look a msyteri!!
Found this gem today:

php:
<?
function logme($what) {
  echo "$what\n";

  exec("echo \"" . $what . "\" >> somelogfile.log ");
}
?>
It's php.

Arntor fucked around with this message at 19:30 on Dec 9, 2008

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
svn blame these gems and tell us more about who wrote them.

Vanadium
Jan 8, 2005

Please tell me that was actually a system and not an exec. :(

Edit: Ignore me, I got my sigil'ing languages mixed up.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
At first I was with you. But I can count at least three strikes against Perl. The function, the param, and the echo. And no my, how dare they.

Vanadium
Jan 8, 2005

Triple Tech posted:

At first I was with you. But I can count at least three strikes against Perl. The function, the param, and the echo. And no my, how dare they.

I figured exec did the same thing everywhere and did not actually look that closely :(

Yeah, perhaps I just assumed the perl guys had come up with a reasonable function definition syntax since I last played with it, but I guess that would be stupid :mad:

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

ani47 posted:

My co-worker said that having a single 'int i' in the beginning of a function instead of one per for loop saves memory.

It has certainly been true in the past that GCC doesn't put a lot of effort into optimizing stack space, including (1) failing to re-use stack slots for different variables based on scope/liveness and (2) failing to "free" stack slots that were promoted to registers. Furthermore, a good compiler shouldn't be harmed by re-using the variable. That said, it's almost certainly not worth the readability hit to "optimize" this by hand.

PrBacterio
Jul 19, 2000

geetee posted:

This is what I'm faced with during my continued attempts to stop using a table called "guid" (with 1 row and 1 bigint column) that is locked and incremented upon every insert.


Matt, if you're a goon, surely you'll understand that I think you're a giant douchebag.
Most of the things in this thread don't even bother me, and I'm very far from knowledgeable about databases, but still this one managed to get to me. That's some seriously :gonk: poo poo

seiken
Feb 7, 2005

hah ha ha

Lexical Unit posted:

My co-worker told me today that const-correctness isn't worth the speed hit.

I'm not a professional programmer or anything (nothing of the sort) but I never make functions const because I've always thought accidentally modifying an object when you didn't mean to would be a fairly uncommon thing, and I always forget to make some const that should be and then have to search through files adding const to other functions that were called by const ones. I've always gotten by fine, is this a horrible thing?

I do use const when passing by reference though I guess.

geetee
Feb 2, 2004

>;[

PrBacterio posted:

Most of the things in this thread don't even bother me, and I'm very far from knowledgeable about databases, but still this one managed to get to me. That's some seriously :gonk: poo poo

It only got worse after I emailed him my reply. Here's more bullshit:

quote:

The problem is usually the slaves falling out of sync for various reasons. The issue always came down to the slave having to generate its own new increment value (because the slave works by just running the same query that was run on the master).

The new form of replication they just released, where it's not just the same query that's run, but some internal data correlation, sounds much better.

Our GUID works very well. And it's simple. It never has an issue. It's never been a performance bottleneck. And it'll easily handle multi-master replication (which we'll probably never need). So why change?

Wow. I might not be a MySQL expert, but I'm pretty sure replication works. I remember reading about some issues with a slave crashing and trying to rerun queries from the binarylog because it wasn't able to mark off where it last left off... but that's a situation completely unrelated to using auto_increment.

New form of replication? Hey what's up, my name is Matt, I read about this new internet thing. MySQL 5 came out over 3 years ago.

But holy poo poo, the last paragraph is where I lost it...

It works very well? Every insert requires 3 queries. (1) Get the next ID, (2) insert the record, (3) increment the "GUID" table. All the while you're locking EVERY table from doing an insert because you need to lock the GUID table which EVERY insert needs to hit.

It's simple? You know what's simplier? Kill yourself.

It never has an issue? See above. Besides re-inventing the wheel (poorly) and all the overhead, it's a pain in the rear end to deal with.

It's never been a performance bottleneck? How could you notice it when it's surrounded by the clusterfuck of an ORM we use? Actually, the irony of this is that we're sitting at a meeting today and he says he wrote code that lets him fetch chunks of a 1000 IDs at a time to speedup the import script he's writing. Really? But it gets better... He claimed 1000 fold performance increase! Wow! I didn't realize fetching a new ID accounts for all operation time. Actually, it just might...

And it'll easily handle multi-master replication (which we'll probably never need)? Oh god... How does it handle it you ask? Each web server has a setting to say how many IDs to increment by. Kind of like the auto_increment setting, but with a million more steps and hoops to jump through.

So why change? :ughh:


I actually said we should look at something like Propel and he immediately shot back something to the effect of: "I've looked at all of those and they're all dead projects."

:smithicide:

beuges
Jul 4, 2005
fluffy bunny butterfly broomstick
I'm working on trying to optimize some C# stuff that keeps falling over due to a complete lack of understanding of any kind of resource management by the contractors that wrote it. Just looking at almost any function makes me want to stab someone.

So I'm trying to trace through some of the program logic, and open up a source file, and see this at the top:

code:
	private static readonly string MESSAGE_TYPE_TAG = "MessageType";
	public static readonly string LEFT_TAG = "<";
	public static readonly string RIGHT_TAG = ">";
	public static readonly string LEFT_CLOSE_TAG = "</";
	private static readonly string COMMAND_TYPE = "Command";
Surely they wouldn't be doing their own xml parsing in .net, what with the whole System.Xml namespace and all :confused:

What do you know

code:
	public static string ExtractTagValue(string tagName, string strMessage)
	{
		string strPollTagStart = LEFT_TAG + tagName + RIGHT_TAG;
		string strPollTagEnd= LEFT_CLOSE_TAG + tagName + RIGHT_TAG;

		int nStartIndex = strMessage.IndexOf(strPollTagStart);
		if(nStartIndex == -1)
			throw new MessageException
				("Invalid formatted message:" + strMessage);
		nStartIndex += strPollTagStart.Length;
		int nEndIndex = strMessage.IndexOf(strPollTagEnd);			
		if(nEndIndex == -1)
			throw new MessageException
				("Invalid formatted message:" + strMessage);
		int nLength = nEndIndex - nStartIndex;
		if(nLength <= 0)
			throw new MessageException
				("Invalid formatted message:" + strMessage);
		return strMessage.Substring(nStartIndex, nLength);
	}
Yay let's create a bunch of new string objects every time we need to query a value out of an xml message (about 10 times per message, processing at least a few hundred messages per second). No wonder the message queues are building up.

Also, that explains their need to do this in their message loop after processing every message:

code:
	GC.Collect();
	GC.WaitForPendingFinalizers();
:suicide:

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

seiken posted:

I'm not a professional programmer or anything (nothing of the sort) but I never make functions const because I've always thought accidentally modifying an object when you didn't mean to would be a fairly uncommon thing, and I always forget to make some const that should be and then have to search through files adding const to other functions that were called by const ones. I've always gotten by fine, is this a horrible thing?

That's pretty much what always happens with const: you run into some code that doesn't tag its types properly, and you either (1) strip the consts out of your new code, (2) spend hours propogating consts through the old code, or (3) add a const_cast and make weeping promises to yourself that you'll clean them all up someday.

netcat
Apr 29, 2008
A friend who interns at some lovely gamedev company around where I live told me they had someone applying for a job, and he sent in a game together with the source code. The code (in C++) was riddled with stuff like this:
code:
int f() {
   int *i = new int;
   ...
   return *i;
}
Needless to say, he didn't get the job.

Lexical Unit
Sep 16, 2003

seiken posted:

I've always gotten by fine, is this a horrible thing?
It kinda sucks :(

I mostly design libraries to be used by other people and one of the primary drives for being const-correct for me is common courtesy. If I provide a method bar() const on my object foo, then users of my library know that calling it isn't going to (conceptually) mutate the object.

Going back and trying to const-correctify something that wasn't designed to be const-correct from the start is painful.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

beuges posted:

:suicide:

This is what the douchebags who wrote the Amazon implementation at my shop did. They were masturbating themselves that they did it in 6 weeks, but maintainance is impossible. It literally takes almost 6 weeks just to fix bugs or update the feeds when Amazon changes the spec.

npe
Oct 15, 2004

geetee posted:

It only got worse after I emailed him my reply. Here's more bullshit:

You know, I'm not going to defend this guy or what he's doing, but I think I've seen this solution before from people who want to simulate Oracle style sequences. Usually though, it's wrapped up in a single procedure to sort of hide the unpleasantness of it.

I guess maybe I'm too used to Oracle, where out of the box we regularly have to query out of a one column, one row table to get certain types of queries to work.

POKEMAN SAM
Jul 8, 2004

netcat posted:

A friend who interns at some lovely gamedev company around where I live told me they had someone applying for a job, and he sent in a game together with the source code. The code (in C++) was riddled with stuff like this:
code:
int f() {
   int *i = new int;
   ...
   return *i;
}
Needless to say, he didn't get the job.

I like to keep my integers on the heap, too, just on the off chance that if my stack gets corrupted my data (integers) will still be correct.

tripwire
Nov 19, 2004

        ghost flow
Ulillillia released the source code for a program he designed in C which converts the sampling rate of PCM wave files.
Check it out:
http://www.ulillillia.us/files/WAVFileSampleRateGeneratorV2Source.zip

TSDK
Nov 24, 2003

I got a wooden uploading this one

tripwire posted:

Ulillillia released the source code for a program he designed in C which converts the sampling rate of PCM wave files.
Check it out:
http://www.ulillillia.us/files/WAVFileSampleRateGeneratorV2Source.zip
Oh my.

Oh my-o-my.

Is that someone on the forums?

Erasmus Darwin
Mar 6, 2001

TSDK posted:

Is that someone on the forums?

Not as far as I know. There have been some GBS threads about him over the years, though. He's internet famous for being crazy. It's been a while since I've read about what he's been up to, but notable things I remember:

  • He has a hobby of taking a small file and manually copying it over and over again to fill up disks.
  • He tried to define the real world in RPG terms with examples such as breaking a stick involving a person's attack value exceeding the stick's defense value.
  • He's made game faqs that focus solely on trying to find the highest point in a video game. He'd try and calculate just how high that translated to in real world units.
  • He's afraid of mirrors.
  • He had imaginary friends named Cinos (Sonic backwards), Sliat (Tails backwards), and Knuckles. I forget the details, but the somehow fit into a pseudo-mystic FF-based framework or something that he believed in.
  • He doesn't like to take showers because he's calculated how much time they waste. But he doesn't like the greasy feel of his dirty fingers on his keyboard. Does that mean that he washes himself, anyway? No. Does that mean that he keeps dryer sheets on top of his keyboard to absorb the grease? Yes.

Witness the insanity first-hand.

His Major Fears -- Mirrors are first, complete with a map of an imaginary department store and an analysis of the logistical difficulties created by the mirrors there.

Erasmus Darwin fucked around with this message at 15:04 on Dec 16, 2008

tripwire
Nov 19, 2004

        ghost flow

TSDK posted:

Oh my.

Oh my-o-my.

Is that someone on the forums?
Nah, not from the forums, although I'm sure a lot of people here are familiar with him :)
Check out his website or youtubes for some flavour: http://www.youtube.com/ulillillia http://www.ulillillia.us


When he says "according to my calculations" he actually means it

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!
In SQL:
code:
Lower(p.town) LIKE Lower(' + '''%lowecasetownname%''' + ')
Yes, that's part of a bigger WTF, a loving stored procedure that concatenates strings to create a SQL statement which it then executes. (This particular section using a series of OR statements to compare a city name to sections of the city.)
:smithicide:

fankey
Aug 31, 2001

From a C# TFTP Server I'm attempting to use
code:
        public string LoggingLevel
        {
            get
            {
                return LogLevel.ToString();
            }
            set
            {
                switch (value)
                {
                    case "Debug":
                        logger.Level = Level.Debug;
                        LogLevel = Level.Debug;
                        break;
                    case "Verbose":
                        logger.Level = Level.Verbose;
                        LogLevel = Level.Verbose;
                        break;
                    case "Config":
                        logger.Level = Level.Config;
                        LogLevel = Level.Config;
                        break;
                    case "Info":
                        logger.Level = Level.Info;
                        LogLevel = Level.Info;
                        break;
                    case "Warning":
                        logger.Level = Level.Warning;
                        LogLevel = Level.Warning;
                        break;
                    case "Exception":
                        logger.Level = Level.Exception;
                        LogLevel = Level.Exception;
                        break;
                }
            }
        }
The Level enum is public in the assembly but they decided to expose all the configuration options as strings instead of enums. And they hard coded those strings instead of using const ones so I get to guess what to set them to. Sometimes they call ToLower() on the string, sometimes not.

Victor
Jun 18, 2004
Haha, there's more WTFage -- if the getter is called without a properly cased string, not only will the property fail to be set, but it won't complain, as it has no default: section. WTF indeed!

fankey
Aug 31, 2001

Victor posted:

Haha, there's more WTFage -- if the getter is called without a properly cased string, not only will the property fail to be set, but it won't complain, as it has no default: section. WTF indeed!
I spend some time attempting to clean up the code - defining some enums and what not. But then I find stuff like
code:
    /// <summary>
    /// Gets or sets the logging method and parameters
    /// </summary>
    public string[] LoggingMethod
    {
      get
      {
        return new string[] { logger.GetType().ToString(), LoggingMethodOptions };
      }
      set
      {
        try
        {
          if (value.Length == 2)
          {
            AddMsg(Level.Debug, "Changing logger to " + value[0] + " with options " + value[1]);
            if (logger.IsOpen)
              logger.Close();
            switch (value[0].ToLower())
            {
              case "windows event":
                logger = new WindowsEventLogger(value[1]);
                break;
              case "sql":
                System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(value[1]);
                logger = new DatabaseLogger(conn, "INSERT INTO [" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " Log] ([EventDatetime], [EventLevel], [EventMessage]) VALUES ('{ts}', '{ln}', '{msg}')");
                logger.EventFormatter = new NSpring.Logging.EventFormatters.PatternEventFormatter("{ts} {msg}");
                break;
              case "text file":
                if (logger.GetType().ToString() != "NSpring.Logging.Loggers.FileLogger")
                  logger = new FileLogger(value[1]);
                break;
              case "xml file":
                if (logger.GetType().ToString() != "NSpring.Logging.Loggers.StreamLogger")
                {
                  System.IO.FileStream LoggerStream = new System.IO.FileStream(value[1], System.IO.FileMode.Append);
                  logger = new StreamLogger(LoggerStream);
                }
                break;
              case "email":
                string[] emailparams = value[1].Split(',');
                if (emailparams.Length == 3)
                  logger = new EmailLogger(emailparams[0], emailparams[1], emailparams[2]);
                break;
              default:
                logger.Open();
                AddMsg(Level.Debug, "Someone tried changing the logger to some type we don't know: " + value[0]);
                break;
            }
            if (!logger.IsOpen)
              logger.Open();
            LoggingMethodOptions = value[1];
          }
          else
          {
            AddMsg(Level.Debug, "Someone tried changing the logger and had " + value.Length.ToString() + " items in the array so we didn't do anything.");
          }
        }
        catch (Exception ex)
        {
          AddMsg(Level.Info, "An error occurred while trying to change the logging method");
          AddMsg(Level.Verbose, "Handled exception: " + ex.Message);
          AddMsg(Level.Debug, "Handled exception at: " + ex.StackTrace);
        }
      }
    }
  }
:sigh: I guess it has some form of error handling. I'm pretty sure 99% of all C# projects on sourceforge are complete garbage.

Adbot
ADBOT LOVES YOU

biznatchio
Mar 31, 2001


Buglord

fankey posted:

I'm pretty sure 99% of all C# projects on sourceforge are complete garbage.

Cross the word C# out of that sentence and your statement remains true.

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