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
Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

piratepilates posted:

Mid is how you get a substring in a string given beginning and end indices in VB6. That's now burned in my brain.
In Grampa Basic, it was MID$.

Adbot
ADBOT LOVES YOU

NihilCredo
Jun 6, 2011

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

piratepilates posted:

Mid is how you get a substring in a string given beginning and end indices in VB6. That's now burned in my brain.

You can use it still today in VB.NET or maybe even C# too.

It's still in VBNet (can use it from other languages by importing Microsoft.VisualBasic) and it's the best thing.

Unlike Substring() it doesn't freak out and throw if the string is too short, it just returns whatever part of the string fell within the given boundaries. For most use cases this will save you a couple of ugly and easily-forgotten calls to Math.Min().

Its only annoyance is that it uses 1-indexing for historical reasons, but it's trivial to make a 0-indexed wrapper (and you can make it an extension method while you're at it).

Prenton
Feb 17, 2011

Ner nerr-nerrr ner

Jabor posted:

Getting the median of three values is exactly what the clamp function does :ssh:

Well, gently caress me.

I always hated LEFT$/RIGHT$/MID$ and looked enviously at Spectrum Basic's A$ (5 TO 10) / A$ ( TO 5) syntax.

Xerophyte
Mar 17, 2008

This space intentionally left blank

Jabor posted:

Getting the median of three values is exactly what the clamp function does :ssh:

It can be but isn't always since clamping to an empty range isn't well defined. To again use GLSL as an example, clamp(x, minVal, maxVal) is defined as min(max(x, minVal), maxVal), so clamp(0.0, 1.0, -1.0) will return -1.0.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

John Big Booty posted:

In Grampa Basic, it was MID$.

It is in vb6 too, because calling MID (or LEFT or RIGHT) without the $ at the end returns Nothing instead of "" when the substring you selected has no contents. So many bugs can be traced to forgetting the $ that our code review practices require a developer to prove he has a good reason to want Nothing as a possible return value in this instance if he leaves $ off of a string manipulation function.

Soricidus
Oct 21, 2010
freedom-hating statist shill

LeftistMuslimObama posted:

our code review practices

I'm the present tense

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



LeftistMuslimObama posted:

It is in vb6 too, because calling MID (or LEFT or RIGHT) without the $ at the end returns Nothing instead of "" when the substring you selected has no contents. So many bugs can be traced to forgetting the $ that our code review practices require a developer to prove he has a good reason to want Nothing as a possible return value in this instance if he leaves $ off of a string manipulation function.

Oh poo poo, I always thought it was the other way around.

All those poor lovely programs that I made very mildly worse :(

Edit: really speaks as to what a coding horror that place was where not only did that never come up in our lovely code review but that I'm pretty sure I was the only person there that knew the difference, and I apparently still got it wrong.

piratepilates fucked around with this message at 14:37 on Aug 31, 2015

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Soricidus posted:

I'm the present tense

We're slowly transitioning to a C# web-based front end, but it takes time to do that in a stable manner for a huge enterprise product and we have to maintain and enhance the older front end in the mean time.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Sedro posted:

Oh boy, that's so convenient! It was probably posted here already but someone made a game of this.

What does it say about me that I'm 10/20? Nothing good, right :v:

brap
Aug 23, 2004

Grimey Drawer
It's ok. I write VB at work now too. It's a terrible language. We are constantly discovering poo poo in it-- subtle bad behaviors, things it allows that lead to runtime errors.

The most recent VB fuckery I found was that comparing an Integer? to an Integer with = produced a result of type Boolean?.
Combine this with the fact that even Option Strict will permit you to provide a Nullable<T> in a context where a T is required, with no complaints, simply causing a runtime error if your Nullable is null, and you get a :psyduck: for the rest of the week.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
I've never used Spring, so I only got 5/20 (and one of those only because I had already seen it on a previous screen). :(

raminasi
Jan 25, 2005

a last drink with no ice

fleshweasel posted:

It's ok. I write VB at work now too. It's a terrible language. We are constantly discovering poo poo in it-- subtle bad behaviors, things it allows that lead to runtime errors.

The most recent VB fuckery I found was that comparing an Integer? to an Integer with = produced a result of type Boolean?.
Combine this with the fact that even Option Strict will permit you to provide a Nullable<T> in a context where a T is required, with no complaints, simply causing a runtime error if your Nullable is null, and you get a :psyduck: for the rest of the week.

This seems pretty reasonable to me :shobon:

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

fleshweasel posted:

It's ok. I write VB at work now too. It's a terrible language. We are constantly discovering poo poo in it-- subtle bad behaviors, things it allows that lead to runtime errors.

The most recent VB fuckery I found was that comparing an Integer? to an Integer with = produced a result of type Boolean?.
Combine this with the fact that even Option Strict will permit you to provide a Nullable<T> in a context where a T is required, with no complaints, simply causing a runtime error if your Nullable is null, and you get a :psyduck: for the rest of the week.

I was with them right up until that last line where VB apparently defeats the entire purpose of Nullable<T>.

I don't tell people my first "real" job was doing .NET... as in VB.Net. I just lie and say it was C#. That was before Nullable and I haven't kept up with what VB has been doing. Still happy with that decision.

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
We had someone submit their code exercise in VB6.

Two weeks ago.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

uncurable mlady posted:

We had someone submit their code exercise in VB6.

Two weeks ago.

Lol. We just have people pseudocode, but the exercises are more akin to Algorithms homework than FizzBuzz type stuff.

loinburger
Jul 10, 2004
Sweet Sauce Jones
I was doing a white board programming exercise for a Java position, and the interviewer complained about poo poo like missing @Override annotations. gently caress that guy.

brap
Aug 23, 2004

Grimey Drawer

GrumpyDoctor posted:

This seems pretty reasonable to me :shobon:

It is not reasonable to return a nullable Boolean as the result of an equality comparison of any two values. Either they are equal or they are not. I'm assuming this is what you're referring to. This is especially bad when you can pass that Boolean? on to a context that wants a Boolean and your program will explode if the answer to the question "are these values equal?" is "Nothing! :downs:"

It's also not reasonable to allow a Nullable<T> to be implicitly unwrapped and provided to a method that consumes a T. C# won't let you do this and VB will. Programmers need to opt in to such unsafe behavior. If you really want an unsafe program then pass in the .Value member to the method.

C# vs. VB fiddles: (I screwed up these examples a few times in haste, sorry.)
https://dotnetfiddle.net/Mk5tMZ
https://dotnetfiddle.net/7ValA0

The C# implementation of equality comparison for nullables, if you're curious:
https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/Nullable.cs#L118
There's an implicit conversion from T to Nullable<T> when you compare to a T. The return type is simply a boolean. If both are null, they're equal; if exactly one is null, they're not equal; otherwise, both are present so do the comparison with the unwrapped values.

brap fucked around with this message at 01:42 on Sep 1, 2015

Winter Stormer
Oct 17, 2012

loinburger posted:

I was doing a white board programming exercise for a Java position, and the interviewer complained about poo poo like missing @Override annotations. gently caress that guy.

gently caress that guy. Jesus.

TheresaJayne
Jul 1, 2011

Winter Stormer posted:

gently caress that guy. Jesus.

I had one like that who complained about missing ; at the end of pseudocode lines.

Soricidus
Oct 21, 2010
freedom-hating statist shill
Your indentation is off by 1/12", this interview is over

Linear Zoetrope
Nov 28, 2011

A hero must cook
I believe your whiteboard coding was using [tabs | spaces] and not [spaces | tabs], and thus you are not qualified for my company. :colbert:

Dylan16807
May 12, 2010

Jsor posted:

I believe your whiteboard coding was using [tabs | spaces] and not [spaces | tabs], and thus you are not qualified for my company. :colbert:

I'm going to interpret that as concatenation and so a requirement of spaces followed by tabs for indenting and aligning. Then I will scream quietly.

Volte
Oct 4, 2004

woosh woosh
I had a teaching assistant that docked me marks on an assignment because the source code, which had to be physically printed out and handed in (and therefore the code was marked visually and never actually run) was not syntax highlighted, due to my poor rear end not owning a colour laser printer. He said having big blocks of comments that are not green makes the code very hard to read. Also I used recursion before we'd covered it in class so I was "making the problem more difficult for yourself to understand and for me to mark". He refused to believe that the code would do what it was supposed to School is a joke and god is dead.

Linear Zoetrope
Nov 28, 2011

A hero must cook
From a KD-Tree test:

code:
		// Exactly pattern match the tree against our expectations
		if let Node{
			point: ref root,
			left: box Node{point: ref left, 
				left: box Node{point: ref l_left, 
					left: box Sentinel, right: box Sentinel}, 
				right: box Node{point: ref l_right, 
					left: box Sentinel, right: box Sentinel}},
			right: box Node{point: ref right, 
				left: box Node{point: ref r_left, 
					left: box Sentinel, right: box Sentinel}, 
				right: box Sentinel}
		} = tree {
			assert_eq!(root, &test[5]);
			assert_eq!(left, &test[1]);
			assert_eq!(l_left, &test[0]);
			assert_eq!(l_right, &test[3]);
			assert_eq!(right, &test[2]);
			assert_eq!(r_left, &test[4]);
		} else {
			panic!("The tree has the wrong structure! {:?}", tree);
		}
This was me. I'm torn between whether this pattern-matching power for test cases is really, really cool or horribly, horribly evil.

qntm
Jun 17, 2009

Dylan16807 posted:

I'm going to interpret that as concatenation and so a requirement of spaces followed by tabs for indenting and aligning. Then I will scream quietly.

Python code:
if True:
  print("this works") # 2-space indentation

if True:
	print("this also works") # tab indentation
	if True:
	  print("and so does this") # tab + 2 spaces
	  if True:
	  	print("and this") # tab + 2 spaces + tab

NihilCredo
Jun 6, 2011

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

fleshweasel posted:

It is not reasonable to return a nullable Boolean as the result of an equality comparison of any two values. Either they are equal or they are not. I'm assuming this is what you're referring to. This is especially bad when you can pass that Boolean? on to a context that wants a Boolean and your program will explode if the answer to the question "are these values equal?" is "Nothing! :downs:"

It's also not reasonable to allow a Nullable<T> to be implicitly unwrapped and provided to a method that consumes a T. C# won't let you do this and VB will. Programmers need to opt in to such unsafe behavior. If you really want an unsafe program then pass in the .Value member to the method.

C# vs. VB fiddles: (I screwed up these examples a few times in haste, sorry.)
https://dotnetfiddle.net/Mk5tMZ
https://dotnetfiddle.net/7ValA0

The C# implementation of equality comparison for nullables, if you're curious:
https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/Nullable.cs#L118
There's an implicit conversion from T to Nullable<T> when you compare to a T. The return type is simply a boolean. If both are null, they're equal; if exactly one is null, they're not equal; otherwise, both are present so do the comparison with the unwrapped values.

You are wrong. DotNetFiddle has Option Strict = Off by default.

If you turn on Option Strict, Nullable<T> is handled correctly. Both of the runtime errors you pointed out become compile-time errors:

https://dotnetfiddle.net/GaJdJ8

quote:

Option Strict On disallows implicit conversions from "Boolean?" to "Boolean"

If you can implicitly unwrap a Nullable<T> in your work project, then it most likely has Option Strict Off as well - either the project properties were changed, or That One Coworker® snuck an "Option Strict off" statement on you somewhere (because he couldn't be arsed to put a bunch of DirectCast()s in his brilliant List(Of Object)-based procedure).

Which would explain why you are "constantly discovering" "terrible things" in VB. ;)

NihilCredo fucked around with this message at 20:12 on Sep 1, 2015

ChickenWing
Jul 22, 2010

:v:

Apparently github is bad at plugins

https://www.humankode.com/security/how-a-bug-in-visual-studio-2015-exposed-my-source-code-on-github-and-cost-me-6500-in-a-few-hours

:stonkhat:

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
Could there be Boolable or Errorable types instead of Nullable types?

kloa
Feb 14, 2007


little late on the clamp chat but:

NihilCredo
Jun 6, 2011

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

MALE SHOEGAZE posted:

Could there be Boolable or Errorable types instead of Nullable types?

Of course. Nullable is just a structure with a couple of useful methods, there's no compiler magic involved beyond the shorthand SomeType?.

Remember, Nullable isn't the C#/VB version of Maybe/Option. It does jack poo poo to protect you from NullReferenceException; checking someNullable.HasValue is not any more powerful than checking someObject isnot nothing, in fact it's a little less comfortable because you can't use the various shorthands available (If(), ?. etc.).

Its anti-NRE usefulness comes strictly from the fact that it acts as a reminder to do those null checks, and you can have the switch from SomeType? to SomeType as a hint that you hopefully did check for null at least once (but obviously nothing guarantees that the unwrapped value didn't get set to Nothing at a later point, so you will still want to null check anyway).

When it comes to actual compiler-enforced features, Nullable's only power is to let you have a boolean/numeric/date variable whose default/unassigned value can be distinguished from a regular False / 0 / 1st Jan 1 A.D. value.

Getting back to your question, you could make both of the things you describe, or you could make a more general Eitherable<SomeType><SomeOtherType> with little effort. Just define the appropriate Narrowing CType and Widening CType operators so you can implicitly assign values. But again, you won't gain any more type safety than before, you'll just save on some typing by checking x.IsFirstType instead of comparing x.GetType() = GetType(FirstType).

code:
public structure Eitherable(of t1, t2)
		
	private enum etype
		thisoneshouldneverexist
		t1
		t2
	end enum

	private _whichtypewasassigned as etype
	
	private sub new() : end sub 

	private sub new(p1 as t1)
		_whichtypewasassigned = etype.t1
		f1 = p1
	end sub
	
	private sub new(p2 as t2)
		_whichtypewasassigned = etype.t2
		f2 = p2
	end sub

	public readonly property f1 as t1
	public readonly property f2 as t2

	public shared widening operator CType(ByVal p1 As t1) As Eitherable(of t1, t2)
		return new eitherable(of t1, t2)(p1)
	End Operator

	public shared narrowing operator CType(ByVal e As Eitherable(of t1, t2)) As t1
		if _whichtypewasassigned = etype.t1 then return f1 else throw new InvalidCastException("lol guessed wrong")
	End Operator

	'same operators for t2

	public readonly property IsFirstType as boolean
		get
			return _whichtypewasassigned = etype.t1
		end get
	end property
	
	'ditto for t2

	'for the reckless among us
	public readonly property value as object
		get
			select case _whichtypewasassigned
				case etype.t1 : return f1
				case etype.t2 : return f2
				case else: throw new exception("someone hosed up")
			end select
		end get
	end property	
		
end structure

NihilCredo fucked around with this message at 22:14 on Sep 1, 2015

brap
Aug 23, 2004

Grimey Drawer

NihilCredo posted:

You are wrong. DotNetFiddle has Option Strict = Off by default.

If you turn on Option Strict, Nullable<T> is handled correctly. Both of the runtime errors you pointed out become compile-time errors:

https://dotnetfiddle.net/GaJdJ8


If you can implicitly unwrap a Nullable<T> in your work project, then it most likely has Option Strict Off as well - either the project properties were changed, or That One Coworker® snuck an "Option Strict off" statement on you somewhere (because he couldn't be arsed to put a bunch of DirectCast()s in his brilliant List(Of Object)-based procedure).

Which would explain why you are "constantly discovering" "terrible things" in VB. ;)

Something is wrong in our project settings I guess, because I was sure we had Option Strict On. Is it a project-wide setting, or does it need to be applied in each source file?
Also possible that some projects in our solution have it on while others don't. Actually, that might be exactly what's wrong. At any rate, unsafety by default is the wrong way to design a language.

NihilCredo
Jun 6, 2011

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

fleshweasel posted:

Something is wrong in our project settings I guess, because I was sure we had Option Strict On. Is it a project-wide setting, or does it need to be applied in each source file?

Also possible that some projects in our solution have it on while others don't. Actually, that might be exactly what's wrong. At any rate, unsafety by default is the wrong way to design a language.

It's a project-wide setting, but you can override it for an individual file by putting Option Strict [on|off] at the top of the file.

There is also a setting in the Visual Studio options that sets the default value for new VB projects you create.

In any case, as far as awful legacy features VB.Net inherited from VB6, Option Strict and hell even Option Explicit aren't that bad. Since we're in the Coding Horrors thread, everybody go check out the On Error Resume Next statement. Bring vodka.

(If you don't fully grasp why OERN is such a horror, or why I have a don't-try-to-find-out-if-I'm-joking rule at work that anybody who puts that in a commit is fired, consider that the following code:

code:
on error resume next
	
dim foo as string = nothing

if foo.length > 100 then console.writeline("dog") else console.writeline("cat")
prints dog.)

NihilCredo fucked around with this message at 22:30 on Sep 1, 2015

Soricidus
Oct 21, 2010
freedom-hating statist shill

NihilCredo posted:

In any case, as far as awful legacy features VB.Net inherited from VB6, Option Strict and hell even Option Explicit aren't that bad. Since we're in the Coding Horrors thread, everybody go check out the On Error Resume Next statement. Bring vodka.

(If you don't fully grasp why OERN is such a horror, or why I have a don't-try-to-find-out-if-I'm-joking rule at work that anybody who puts that in a commit is fired, consider that the following code:

code:
on error resume next
	
dim foo as string = nothing

if foo.length > 100 then console.writeline("dog") else console.writeline("cat")
prints dog.)

now try vbscript, where it's literally the only way to handle errors. enjoy trying to predict which operations can cause an error and then manually checking the global error object after every single one! or what everyone actually does, which is leaving it to the next guy to figure out why things suddenly start failing silently five years down the line.

NihilCredo
Jun 6, 2011

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

Soricidus posted:

now try vbscript, where it's literally the only way to handle errors. enjoy trying to predict which operations can cause an error and then manually checking the global error object after every single one! or what everyone actually does, which is leaving it to the next guy to figure out why things suddenly start failing silently five years down the line.

poo poo, it didn't even have On Error Goto? I thought that one at least was alright, since it's pretty much a primitive try/catch block. Other than the whole "no exception object" thing.

fake edit: SO'd it, apparently you're supposed to put dangerous operations into their own OERN-less procedures, which will return immediately on an exception, and you call them from an OERN procedure in which you check the return / global variables immediately after calling one of those dangerous functions. I guess it encouraged proper function splitting at least? :shrug:

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
OERN is just a slightly weirder version of the standard C error handling scheme of return code + errno.

Plorkyeran fucked around with this message at 01:00 on Sep 2, 2015

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Plorkyeran posted:

OERN is just a slightly weirder version of the standard C error handling scheme of return code + errno.

I think you mean the standard C error handling scheme of failing to check return codes and continuing blindly after an operation fails goto fail.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

The horror is that he committed AWS keys in his source code.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
I find it pretty funny that someone did $6,500 of SHA256 hashes in a few hours.

Kazinsal
Dec 13, 2011


Blinkz0rz posted:

The horror is that he committed AWS keys in his source code.

Adding to that, the immediate response by the masses of internet know-it-all programmers was to blame Microsoft.

The idiot who committed AWS keys could have omitted VS from the post title, but then people would just call him a loving idiot for committing AWS keys. Because he is.

Adbot
ADBOT LOVES YOU

brap
Aug 23, 2004

Grimey Drawer
It's a little of column A, little of column B. It's a bad bug that Visual Studio creates a public repository when you check the private checkbox. It also makes no sense to commit API keys in version control.

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