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
Surprise T Rex
Apr 9, 2008

Dinosaur Gum
Pseudo-code recreation of something I found yesterday.

code:
try 
{
	connect_to_thing(username1)
}
catch(Exception ex)
{
	try
	{
		connect_to_thing(username2)
		disconnect_user(username1)
	}
	catch(Exception ex)
	{
		try
		{
			connect_to_thing(username3)
			disconnect_user(username1)
			disconnect_user(username2)
		}
		catch(Exception ex)
		{
			Throw new Exception(ex.Message)
		}
	}
}	
I don't know what goes through your head to write stuff like this. Especially as it basically ends with "No, don't throw an error! throw an error!"

Adbot
ADBOT LOVES YOU

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
"Use a loop? What for? I don't have any arrays!" :v:

Polio Vax Scene
Apr 5, 2009



That "throw an error using another error" thing is all to prevalent in our code here. No, no, I didn't want the stack trace, that's fine...

But hey, at least he's disconnecting the users after they fail to connect!

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



To give the benefit of the doubt, the disconnect_user() function might be doing some cleanup, but it annoys the poo poo out of me that they come after the connect_to_thing() functions.

Surprise T Rex
Apr 9, 2008

Dinosaur Gum

Snapchat A Titty posted:

To give the benefit of the doubt, the disconnect_user() function might be doing some cleanup, but it annoys the poo poo out of me that they come after the connect_to_thing() functions.

In this context it's purely because you have to connect as a user to disconnect other users.

I can't decide which bit is worse here. I just really hate this guy's tendency to catch an exception and re-throw it. Or worse, leave it blank and let the thing fail silently!

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost
Had to fix some javascript code from our old VB.NET solution. It's a page made up of multiple iFrames, and the scrolling container for one of the iframes was not being reset correctly after some HTML was removed from it. We don't do this type of iFrame poo poo anymore, but until we can rewrite these pages into C# we're stuck.

So while trying to figure out what was going on, I saw this.

code:
var determineHeight = function ()
{
	if (iframe.contentWindow.document.body == null)
	{
		return 0;
	}
	if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
	{
		return iframe.contentWindow.document.body.scrollHeight;
	}
	else
	{
		return iframe.contentWindow.document.body.scrollHeight;
	}
}	
if (type == 'body')
{
// ...
}
else{
	var frameHeight = determineHeight();
	if (frameHeight == 0)
	{
	// ...
	}
	else
	{
	if (Sys.Browser.agent == Sys.Browser.InternetExplorer || Sys.Browser.name == "Firefox")
	{
		this.iframe.height = frameHeight + 10;
	}
	else
	{
		this.iframe.height = frameHeight;
	}
    }
}
Now determineHeight was not originally written like that. Someone changed the else case to return the same thing. Not sure why they did not get rid of it right then and there. Also it's wrong anyway, since determineHeight is used to determine the "height" of the inner content of the iframe after HTML was added or removed from it. Adding HTML gets the correct "scroll height", but removing it does not reset it. I think they wanted clientHeight.

I don't know what's with the hardcoded "10" pixels either. I'm guessing that's meant to compensate for the toolbar? Who knows :v:. Also we had framework and an enum for the users browser. Yet here they just went the hardcoded approach. Thanks guys!

titaniumone
Jun 10, 2001

I used to work in an area where a new team was started by grabbing a bunch of self-proclaimed "wizards" from a bunch of other teams. They were writing a massive, over-engineered, overly-complex system which would produce XML-but-not-really as its endpoint.

I was supposed to do some of the initial design for how these XML files would be parsed and stored. When I asked for schemas, I was told "we don't have any and aren't going to make any, just look at some of the files on disk in the development environment and use them as examples".

When I told them this was a totally inappropriate way for me to attempt to write a design and that it wasn't going to be accurate or reliable enough, they complained that I was "difficult to work with". Since this team was a bunch of wizards, I of course lost this fight.

It was a great area to work in. I eventually churned out a garbage, gibberish design for the sake of having produced one, and left the area forever.

Zorro KingOfEngland
May 7, 2008

Java code:
catch (Exception e) {
			e.printStackTrace(); // 1
			throw new Exception(e.getMessage());
		}
o...kay. Let's see where this exception goes

Java code:
}
catch (Exception e) {
	logger.error("EXCEPTION [DOING THING]", e); // 2
	e.printStackTrace(); // 3
	throw new HibernateException(e.getMessage());
}
Well this is something. Let's see where this exception goes

Java code:

catch (Exception e) {
	logger.error("GENERAL EXCEPTION [DOING THING]", e); // 4
	e.printStackTrace(); // 5
	if (transaction.isActive()) {
		transaction.rollback();
	}
	throw new Exception((new StringBuilder("Problem [DOING THING WITH ID]:")).append(Id).toString());
}
and then finally, for good measure we log the exception again.

Java code:
catch(Exception e)
{
	e.printStackTrace(); // 6
        action = "failure";
}
Comments are mine. One exception shows up in the log 6 times, in slightly different forms.

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

Zorro KingOfEngland posted:

Comments are mine. One exception shows up in the log 6 times, in slightly different forms.

I was trying to speed up a server of mobile phone (at the time, mostly WAP) applications in the early 2000s. I discovered, at one point, that through logging of this sort one single WAP request would generate around 10MB of debugging information...

IMlemon
Dec 29, 2008
Excessive logging is a pain in the rear end. How about you write normal software and maybe a test or two instead of filling every single method with log calls? One particularly bad component I had to work with was actually logging every method start/end and parameters for each function. 80% of code in that thing was logging.

awesmoe
Nov 30, 2005

Pillbug

IMlemon posted:

Excessive logging is a pain in the rear end. How about you write normal software and maybe a test or two instead of filling every single method with log calls? One particularly bad component I had to work with was actually logging every method start/end and parameters for each function. 80% of code in that thing was logging.
Did you know that if you have too much logging, you can turn it off with your logging config, but if you have too little logging, you can't turn it on? makes u think...

Westie
May 30, 2013



Baboon Simulator

awesmoe posted:

Did you know that if you have too much logging, you can turn it off with your logging config, but if you have too little logging, you can't turn it on? makes u think...

But what if you have no logging config?

awesmoe
Nov 30, 2005

Pillbug

Westie posted:

But what if you have no logging config?
cat logfile | grep -v spam1 | grep -v spamline2 |grep -v "line you think is spam but is actually vital"

Westie
May 30, 2013



Baboon Simulator

awesmoe posted:

cat logfile | grep -v spam1 | grep -v spamline2 |grep -v "line you think is spam but is actually vital"

That made me laugh way more than it should have done.

substitute
Aug 30, 2003

you for my mum
Walked into work this morning to see this email.

like, my manager or something posted:

I'm guessing there was a wholesale reload of the derpderpderp table recently. I had fixed/populated several derps and now all of that is gone. I'll fix it again, but we need to avoid wholesale replacement of production tables unless its agreed that a table can be replaced.

Why yes, I did just update the table, from DEV, yesterday. ...Sorry...?

ijustam
Jun 20, 2005

IMlemon posted:

Excessive logging is a pain in the rear end. How about you write normal software and maybe a test or two instead of filling every single method with log calls? One particularly bad component I had to work with was actually logging every method start/end and parameters for each function. 80% of code in that thing was logging.

This is how we write software but mainly because a lot of times it's literally the only thing you get from a customer that's useful. The more information in the logs, the better. Sometimes I'll run into code where there's maybe 5 log lines in the file and it's loving worthless. Just keep the logging level turned down during peacetime and there's no problem.

HFX
Nov 29, 2004

ijustam posted:

This is how we write software but mainly because a lot of times it's literally the only thing you get from a customer that's useful. The more information in the logs, the better. Sometimes I'll run into code where there's maybe 5 log lines in the file and it's loving worthless. Just keep the logging level turned down during peacetime and there's no problem.

To add fuel to this fire, logging can help you discover the multi threading bugs in a way that is hard to reproduce with unit tests.

That said, it is good to setup good logging levels and not log everything.

IMlemon posted:

Excessive logging is a pain in the rear end. How about you write normal software and maybe a test or two instead of filling every single method with log calls? One particularly bad component I had to work with was actually logging every method start/end and parameters for each function. 80% of code in that thing was logging.

There is nothing wrong with this. There are even methods for moving these log statements where they are separate from the business logic.

Finally, for some platforms (embedded), logs like this can be one of the few ways to find bugs.

HFX fucked around with this message at 18:23 on Sep 10, 2014

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Notch is a genius; he's manage to monetize coding horrors:
http://games.slashdot.org/story/14/09/09/2334235/report-microsoft-to-buy-minecraft-studio-for-2bn

That's like, at least $5 for each horror

pazurek
Dec 24, 2011
I did this for prestashop

quote:

UPDATE `product_lang` SET `link_rewrite` = REPLACE( TRIM( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( TRIM(LOWER(`name`)) , 'ą', 'a') , 'ć', 'c') , 'ę', 'e') , 'ł', 'l') , 'ń', 'n') , 'ó', 'o') , 'ś', 's') , 'ż', 'z') , 'ź', 'z') , '-', ' ') , '(', ' ') , ')', ' ') , ';', ' ') , ':', ' ') , ',', ' ') , '.', ' ') , '/', ' ') , '!', ' ') , '+', ' ') , '*', ' ') , '\'', ' ') , '"', ' ') , ' ', ' ') , ' ', ' ') , ' ', ' ') , ' ', ' ') , ' ', ' ') , ' ', ' ') , ' ', ' ') , ' ', ' ') ) , ' ', '-');

:tizzy:

Corla Plankun
May 8, 2007

improve the lives of everyone
I think you just completely changed my opinion about the utility and readability of regular expressions.

pazurek
Dec 24, 2011
Too bad it's mysql.

quote:

Currently REPLACE function does not support regular expression so if you need to replace a text string by a pattern you need to use MySQL user defined function (UDF) from external library, check it out here MySQL UDF with Regex

Spatial
Nov 15, 2007

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near <line after the actual error> on line whatever.

Pleb. :smug:

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

Drastic Actions posted:

Had to fix some javascript code from our old VB.NET solution. It's a page made up of multiple iFrames, and the scrolling container for one of the iframes was not being reset correctly after some HTML was removed from it. We don't do this type of iFrame poo poo anymore, but until we can rewrite these pages into C# we're stuck.

So while trying to figure out what was going on, I saw this.

code:
var determineHeight = function ()
{
	if (iframe.contentWindow.document.body == null)
	{
		return 0;
	}
	if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
	{
		return iframe.contentWindow.document.body.scrollHeight;
	}
	else
	{
		return iframe.contentWindow.document.body.scrollHeight;
	}
}

This is my favorite if-else block in the entire world. I'm a pretty lovely programmer but man, I've at least never done poo poo like that.

I mean, how does one not even see that the whole block will literally do the same exact thing?

EssOEss
Oct 23, 2006
128-bit approved
Well, it appears to be JavaScript, so I can certainly imagine them going "search and replace and gently caress it, ship it". Perhaps there was something else in there that they replaced but they never looked at the code? That seems to be how most people operate on horrible codebases - just do something and if it seems to work, go with it.

Pythagoras a trois
Feb 19, 2004

I have a lot of points to make and I will make them later.
I need to unsubscribe from the /r/javascript subreddit, it only makes me angry.

http://node-os.com/

bone app the teeth
May 14, 2008

Cheekio posted:

I need to unsubscribe from the /r/javascript subreddit, it only makes me angry.

http://node-os.com/

https://github.com/NodeOS/NodeOS/issues/7

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

Cheekio posted:

I need to unsubscribe from the /r/javascript subreddit, it only makes me angry.

http://node-os.com/

The little gobshite's got no loving clue what it takes to make an operating system.

He's layered /usr/bin/env and /etc/resolv.conf lower than the C library, which he just copies wholesale out of the host operating system, not even tracing the dependencies from the node.js binary he just built.

Now, what he should've done is build a minimal libc like musl, and statically link against that.
If you need env too, you can build the one out of busybox.

qntm
Jun 17, 2009

pliable posted:

This is my favorite if-else block in the entire world. I'm a pretty lovely programmer but man, I've at least never done poo poo like that.

I mean, how does one not even see that the whole block will literally do the same exact thing?

Maybe they copied and pasted the return iframe.contentWindow.document.body.scrollHeight; line but forgot to modify the pasted version. Maybe a codebase-wide find/replace operation made those two blocks identical when they weren't before. People overlook things. It happens.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

There was going to be a psyduck with his head exploding here, but at this point I've just given up.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Edison was a dick posted:

The little gobshite's got no loving clue what it takes to make an operating system.
I am shocked, shocked, to discover that the guy who thinks it would be a good idea to base an OS on Javascript is not a highly-skilled engineer.

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

ultramiraculous posted:

There was going to be a psyduck with his head exploding here, but at this point I've just given up.

If they want sharding like that, they should probably make their OS image an initramfs, stick Ceph tools in there, authenticate with a Ceph server, and mount the filesystem from that.

Soricidus posted:

I am shocked, shocked, to discover that the guy who thinks it would be a good idea to base an OS on Javascript is not a highly-skilled engineer.

I'm only paying attention to this, because the last time my boss heard of something like this I had to explain how it worked and why we shouldn't do it.

Edison was a dick fucked around with this message at 21:59 on Sep 11, 2014

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

If you're looking to make an OS that's primarily driven by JavaScript, and you don't start from either ChromeOS or FirefoxOS, I think you might be making a mistake (in addition to other, higher-level mistakes).

"psyduck" would be a good project name for this thing, though.

Polio Vax Scene
Apr 5, 2009



Yeah just remove everything between your commas there. Although I assume that's what your statement in parenthesis is referring to.

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

Subjunctive posted:

If you're looking to make an OS that's primarily driven by JavaScript, and you don't start from either ChromeOS or FirefoxOS, I think you might be making a mistake (in addition to other, higher-level mistakes).

I get the appeal of writing your userland in your favourite language, and stripping out the bits of the operating system you're not going to use (such as your shell interpreter if you're only ever going to interact with the system via the web application, and you've managed to build an entire software stack that avoids calling system()).
I've heard of projects successfully doing this with Lua.
Hell, the MirageOS guys went the next step along and embed the applications in the kernel, completely ignoring any userland.

But Node.js is completely unsuitable for system software, it's just happening because Node's trendy. I just hope it doesn't catch on, since we could end up with clueless idiots wading into the already pretty moronic init system debate.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Edison was a dick posted:

I just hope it doesn't catch on
I'd say it has roughly the same chance as all the other attempts to build an OS with every trendy-language-of-the-month ever, which is to say: lol.

ExcessBLarg!
Sep 1, 2001
Fortunately there's a self-selection thing going on here. The folks experienced and competent enough to implement an operating system will recognize that it makes no sense to reinvent the wheel and will just contribute to Chrome OS, Firefox OS, Open webOS or whatever. The only folks who think this effort is a good idea will derail themselves long before they can make any actual progress.

As a bonus, it keeps the trendy incompetents from noising up mailing lists of decent projects.

JawnV6
Jul 4, 2004

So hot ...
Then all the experienced folks die off and we're left with a bevy of talent squandered on frontends like moths to a flame.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Some bevies are really better off squandered.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I wonder if you could build an OS in Inform 7.

Adbot
ADBOT LOVES YOU

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Dr. Stab posted:

I wonder if you could build an OS in Inform 7.

Given the ratio of discussion to code on the Node-OS github I'd guess it would look more or less identical.

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