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
EssOEss
Oct 23, 2006
128-bit approved
Unless you open thousands of files per second and thus have to bear the cost of generating thousands of stack traces per second. In that case, you're better off checking first (in addition to handling the exception).

Adbot
ADBOT LOVES YOU

antpocas
Jun 30, 2004

IF THIS POST ISN'T ABOUT GLORIOUS SALAZAR YOU MUST BE READING IT WRONG
VB.Net
code:
    Public Shared Function GetUserAdminRegion() As RegionalEngine.enUserGeoRegion
        Return UsersEngine.AppPrincipal IsNot Nothing AndAlso UsersEngine.AppPrincipal.Identity.AdminRegion
    End Function
UsersEngine.AppPrincipal.Identity.AdminRegion is an integer.
RegionalEngine.enUserGeoRegion is an enum.
what

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Edison was a dick posted:

What if it's gone by the time you open it? You need to handle the exception when that happens anyway, so you might be better off not checking first.

No, you should probably check first.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

antpocas posted:

VB.Net
code:
    Public Shared Function GetUserAdminRegion() As RegionalEngine.enUserGeoRegion
        Return UsersEngine.AppPrincipal IsNot Nothing AndAlso UsersEngine.AppPrincipal.Identity.AdminRegion
    End Function
UsersEngine.AppPrincipal.Identity.AdminRegion is an integer.
RegionalEngine.enUserGeoRegion is an enum.
what

NihilCredo posted:

as with nearly everything that's hosed up in VB.NET, the answer is "you didn't activate option strict in your project"

antpocas
Jun 30, 2004

IF THIS POST ISN'T ABOUT GLORIOUS SALAZAR YOU MUST BE READING IT WRONG

NihilCredo posted:

as with nearly everything that's hosed up in VB.NET, the answer is "you didn't activate option strict in your project"
This is my 4th week it's not my project :(

We're getting rid of everything that's VB.Net though. I also found this
code:
    Public Function NoNothing(ByVal obj As Object, ByVal defeito As Object) As Object
        If obj Is Nothing Then
            Return defeito
        Else
            Return obj
        End If
    End Function
which I'm pretty sure is the same as If(arg1, arg2)

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.
if (foo) {
Bar();
Baz();
}
else {
Baz();
Bar();
}

Had to spend 20 minutes making sure that there weren't side effects before nuking it. There was even a "wtf is this poo poo" comment, but I guess others aren't willing to delve into the madness. :cthulhu::hf::smith:

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

leper khan posted:

if (foo) {
Bar();
Baz();
}
else {
Baz();
Bar();
}

Had to spend 20 minutes making sure that there weren't side effects before nuking it. There was even a "wtf is this poo poo" comment, but I guess others aren't willing to delve into the madness. :cthulhu::hf::smith:

I've seen this pattern before, and in my experience it has usually been using a shared field in multiple methods in such a way that the order of calling those methods is important. Something like this:

code:
public class AThing
{
	//because of course everything is public
	public int value;
	
	public int DoThing(bool foo)
	{
		if(foo)
		{
			Bar();
			Baz();
		}
		else
		{
			Baz();
			Bar();
		}
		
		return value;
	}
	
	public void Bar()
	{
		value++;
	}
	
	public void Baz()
	{
		value *= value;
	}
}

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Cuntpunch posted:

I've seen this pattern before, and in my experience it has usually been using a shared field in multiple methods in such a way that the order of calling those methods is important. Something like this:

code:

public class AThing
{
	//because of course everything is public
	public int value;
	
	public int DoThing(bool foo)
	{
		if(foo)
		{
			Bar();
			Baz();
		}
		else
		{
			Baz();
			Bar();
		}
		
		return value;
	}
	
	public void Bar()
	{
		value++;
	}
	
	public void Baz()
	{
		value *= value;
	}
}

Yes, that's why I had to spend 20 minutes reading the terrible code before ripping it out. The effects of Bar() and Baz() in this case were mutually exclusive. :smith:

In other news one of my coworkers unironically prefers monodevelop to VS. Some things I know better than to delve into. :iiam:

Space Kablooey
May 6, 2009


leper khan posted:

In other news one of my coworkers unironically prefers monodevelop to VS. Some things I know better than to delve into. :iiam:

:sever:

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

antpocas posted:

This is my 4th week it's not my project :(

We're getting rid of everything that's VB.Net though. I also found this
code:
    Public Function NoNothing(ByVal obj As Object, ByVal defeito As Object) As Object
        If obj Is Nothing Then
            Return defeito
        Else
            Return obj
        End If
    End Function
which I'm pretty sure is the same as If(arg1, arg2)

might as well admit defeito now.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

LeftistMuslimObama posted:

might as well admit defeito now.

speaking of which, my Portuguese is rudimentary but I'm pretty confident "defeito" means *fault*, not default

antpocas
Jun 30, 2004

IF THIS POST ISN'T ABOUT GLORIOUS SALAZAR YOU MUST BE READING IT WRONG

NihilCredo posted:

speaking of which, my Portuguese is rudimentary but I'm pretty confident "defeito" means *fault*, not default
The expression "por defeito" means "by default", although "por predefinição" is arguably more correct as "defeito" on its own does not have a "automatically selected option unless another is provided" meaning. The closest translation of "defeito" is "defect", which is what the person who wrote that code has in their brain

BlackMK4
Aug 23, 2006

wat.
Megamarm
code:
<?php
    /*
        This is a PHP comment so no one sees it other than
        the poor soul (you) that has to crack this open in the future.
        
        DO NOT REMOVE THE WEIRD COMMENTS IN THE HTML BELOW, THEY ARE
        THERE FOR A REASON. (REMOVES SPACE BETWEEN INLINE-BLOCK ITEMS)
    */
?>
<div class="checkbox--div">
    <input id="numbered-1" type="checkbox" class="checkbox--numbered" name="1" checked="checked">
    <label for="numbered-1" class="checkbox--numbered-label">1</label>
</div><!--
--><div class="checkbox--div">
    <input id="numbered-2" type="checkbox" class="checkbox--numbered" name="2">
    <label for="numbered-2" class="checkbox--numbered-label">2</label>
</div><!--
--><div class="checkbox--div">
    <input id="numbered-3" type="checkbox" class="checkbox--numbered" name="3">
    <label for="numbered-3" class="checkbox--numbered-label">3</label>
</div><!--
--><div class="checkbox--div">
    <input id="numbered-4" type="checkbox" class="checkbox--numbered" name="4">
    <label for="numbered-4" class="checkbox--numbered-label">4</label>
</div><!--
--><div class="checkbox--div">
    <input id="numbered-5-plus" type="checkbox" class="checkbox--numbered" name="5-plus">
    <label for="numbered-5-plus" class="checkbox--numbered-label">5+</label>
</div>

return0
Apr 11, 2007

BlackMK4 posted:

code:
<?php
    /*
        This is a PHP comment so no one sees it other than
        the poor soul (you) that has to crack this open in the future.
        
        DO NOT REMOVE THE WEIRD COMMENTS IN THE HTML BELOW, THEY ARE
        THERE FOR A REASON. (REMOVES SPACE BETWEEN INLINE-BLOCK ITEMS)
    */
?>
<div class="checkbox--div">
    <input id="numbered-1" type="checkbox" class="checkbox--numbered" name="1" checked="checked">
    <label for="numbered-1" class="checkbox--numbered-label">1</label>
</div><!--
--><div class="checkbox--div">
    <input id="numbered-2" type="checkbox" class="checkbox--numbered" name="2">
    <label for="numbered-2" class="checkbox--numbered-label">2</label>
</div><!--
--><div class="checkbox--div">
    <input id="numbered-3" type="checkbox" class="checkbox--numbered" name="3">
    <label for="numbered-3" class="checkbox--numbered-label">3</label>
</div><!--
--><div class="checkbox--div">
    <input id="numbered-4" type="checkbox" class="checkbox--numbered" name="4">
    <label for="numbered-4" class="checkbox--numbered-label">4</label>
</div><!--
--><div class="checkbox--div">
    <input id="numbered-5-plus" type="checkbox" class="checkbox--numbered" name="5-plus">
    <label for="numbered-5-plus" class="checkbox--numbered-label">5+</label>
</div>


Is this actually bad (the comments to not have spacing, rather than the repetition in the HTML itself)?

xzzy
Mar 5, 2009

It's one of the more ham-fisted ways I've come across for dealing with the way browsers handle whitespace in html.

But it shouldn't be an issue in the era of css as no layout should be so rigid that an extra space breaks everything.

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.
Actually it's super annoying to work around.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
the real horror is html whitespace rules

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings
Is it bothering anybody else that the input tags aren't closed, and the divs aren't aligned?

vOv
Feb 8, 2014

No, because input tags don't have closing tags (and including them is technically against spec even though any reasonable parser will do the right thing).

BlackMK4
Aug 23, 2006

wat.
Megamarm

xzzy posted:

It's one of the more ham-fisted ways I've come across for dealing with the way browsers handle whitespace in html.

But it shouldn't be an issue in the era of css as no layout should be so rigid that an extra space breaks everything.
Breaking isn't the issue, following up on some of the poo poo that designers do is.

BlackMK4 fucked around with this message at 02:43 on Aug 4, 2016

Carbon dioxide
Oct 9, 2012

Suspicious Dish posted:

the real horror is html whitespace rules

There are rules? I thought it was just every browser by itself in the wild, wild west.

vOv
Feb 8, 2014

xzzy posted:

It's one of the more ham-fisted ways I've come across for dealing with the way browsers handle whitespace in html.

But it shouldn't be an issue in the era of css as no layout should be so rigid that an extra space breaks everything.

If you're trying to put multiple 'blocks' next to each other like this then having whitespace fucks up your design. Compare the top row vs the middle row. The usual fix I've seen is to set the font-size to 0 and then restore it in your children, like in the bottom row, but that's annoying and hacky.

Xarn
Jun 26, 2015

vOv posted:

If you're trying to put multiple 'blocks' next to each other like this then having whitespace fucks up your design. Compare the top row vs the middle row. The usual fix I've seen is to set the font-size to 0 and then restore it in your children, like in the bottom row, but that's annoying and hacky.

Who the gently caress thought that is sane behaviour?

redleader
Aug 18, 2005

Engage according to operational parameters

vOv posted:

No, because input tags don't have closing tags (and including them is technically against spec even though any reasonable parser will do the right thing).

HTML 5's must-not-have-an-end-tag tags are the real horror.

qntm
Jun 17, 2009

Xarn posted:

Who the gently caress thought that is sane behaviour?

Suppose you're using HTML to write text.

HTML code:
<p>Here is some <b>bold text</b> <i>and some italicised text</i></p>
If you ignored whitespace between elements, that would render as:

quote:

Here is some bold textand some italicised text

Or maybe even

quote:

Here is somebold textand some italicised text

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings
code:
namespace Senior.Developers
{
	public static class Constants
	{
		public const string VERSION = "VERSION";
		public const string ENVIRONMENT = "ENVIRONMENT";
		public const string FILE_LOCATION = "File_Location";
		public const string USER_NAME = "User_Name";
		//Continues on for 500 more lines
	}
}

xzzy
Mar 5, 2009

vOv posted:

If you're trying to put multiple 'blocks' next to each other like this then having whitespace fucks up your design. Compare the top row vs the middle row. The usual fix I've seen is to set the font-size to 0 and then restore it in your children, like in the bottom row, but that's annoying and hacky.

My suggestion is not using inline elements for making tabs. :v:

To be fair, I agree 100% that html's handling of whitespace is idiotic, but in general, it's super common for designers to create their own problems by using the wrong tools.

BlackMK4
Aug 23, 2006

wat.
Megamarm

xzzy posted:

My suggestion is not using inline elements for making tabs. :v:

To be fair, I agree 100% that html's handling of whitespace is idiotic, but in general, it's super common for designers to create their own problems by using the wrong tools.

The code I was referencing above is used for this:

Xarn
Jun 26, 2015

qntm posted:

Suppose you're using HTML to write text.

HTML code:
<p>Here is some <b>bold text</b> <i>and some italicised text</i></p>
If you ignored whitespace between elements, that would render as:

quote:

Here is some bold textand some italicised text


Ok, after messing around with the fiddle it makes more sense, but still feels weird, ie
HTML code:
<i> </i> <i> </i>
is collapsed into single space (or no space if it happens to be trailing/leading), even if there is a CSS that makes such changes visible (ie background color being black).

Xarn fucked around with this message at 16:26 on Aug 4, 2016

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Cuntpunch posted:

code:
namespace Senior.Developers
{
	public static class Constants
	{
		public const string VERSION = "VERSION";
		public const string ENVIRONMENT = "ENVIRONMENT";
		public const string FILE_LOCATION = "File_Location";
		public const string USER_NAME = "User_Name";
		//Continues on for 500 more lines
	}
}

we do i18n sorta this way in vb because theres not really a better way. we use a tool to find repeated strings and tokenize them for you, though.

ive also seen people do this with strings that get typod in code a lot since then the intellisense helps you out, you just have to remember theres a constant to use instead of typing the string out. but without context im assuming this is dumber than either of those things.

xzzy
Mar 5, 2009

BlackMK4 posted:

The code I was referencing above is used for this:


Have you discovered flex boxes yet? They rocked my world.

http://codepen.io/xzzy/pen/akRmwg

Look at that crazy gives no shits about whitespace html! :v:

(prior to knowing about flex boxes I did this with inline list elements, css is uglier but it works on all browsers in the last 10 years)

xzzy fucked around with this message at 16:43 on Aug 4, 2016

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

LeftistMuslimObama posted:

we do i18n sorta this way in vb because theres not really a better way. we use a tool to find repeated strings and tokenize them for you, though.

ive also seen people do this with strings that get typod in code a lot since then the intellisense helps you out, you just have to remember theres a constant to use instead of typing the string out. but without context im assuming this is dumber than either of those things.

Probably 90% of these Constants are only ever used in a single place in the entire application. And seem to be just dodging ToLower/ToUpper stuff. In some cases it's just a like...weird roundabout way to feed a string value into ConfigurationManager.AppSettings[Constants.SAVE_PATH] in a single place in the entire application. I can totally see this sort of lookup table or whatever being used for localization, sure! But one of our terrible offshore developers has an insane hardon that *anything* in the logic that requires a string should probably instead refer to a constant. Even if it's one-off, or something as insane as

code:
public static readonly Color WhiteText = Color.White;

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Cuntpunch posted:

I can totally see this sort of lookup table or whatever being used for localization, sure! But one of our terrible offshore developers has an insane hardon that *anything* in the logic that requires a string should probably instead refer to a constant.

Look, hardcoded values are bad, mkay? So you should always, always use a constant instead. Want to tell if a number is even? "if (n % 2)" is bad; "if (n % TWO)" is much safer!

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

redleader posted:

HTML 5's must-not-have-an-end-tag tags are the real horror.

why?

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

TooMuchAbstraction posted:

Look, hardcoded values are bad, mkay? So you should always, always use a constant instead. Want to tell if a number is even? "if (n % 2)" is bad; "if (n % TWO)" is much safer!

I've tried to suggest that the acronym "USA" is unlikely to change any time soon, but it falls on deaf ears. Constants.USA = "USA" it is.

Spatial
Nov 15, 2007

It complicates my HTML regex! :mad:

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Cuntpunch posted:

I've tried to suggest that the acronym "USA" is unlikely to change any time soon, but it falls on deaf ears. Constants.USA = "USA" it is.

Shouldn't it be I18N.ToLocale(Constants.CURRENT_LOCALE, Constants.USA);

You know, to allow for USA vs 미국 or w/e. :smithicide:

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Even if they're never going to change, using constants for strings means that the compiler can catch typos.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Plorkyeran posted:

Even if they're never going to change, using constants for strings means that the compiler can catch typos.

Unless the string only is used once in the code anyway.

Adbot
ADBOT LOVES YOU

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.

Plorkyeran posted:

Even if they're never going to change, using constants for strings means that the compiler can catch typos.
Or a typo ends up permanent. :unsmigghh:

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