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
xzzy
Mar 5, 2009

Klades posted:

Why in the world would you do cat | cat.

It was demonstrating how easy pipes are in bash, not a code sample. :ssh:

Python's subprocess module is kind of garbage. I mean, it does everything you need to do, but the interface sucks. I have to double check the documentation just about every single time I need to use them again.

But I'll never forget how to use a |. :v:

Adbot
ADBOT LOVES YOU

Klades
Sep 8, 2011

xzzy posted:

It was demonstrating how easy pipes are in bash, not a code sample. :ssh:

Fair enough. I'm not experienced enough in bash voodoo to immediately dismiss something like that but it didn't look like a thing you would actually want to do so I got confused.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Klades posted:

I mean I take your point, if you wanted to do something like grep | grep it would be comparatively messy in a scripting language, but then that's why you can do things like (Ruby, anyway):
code:

somevariable = `grep #{filename} "#{pattern}" | grep "#{pattern2}"`
Yes, vulnerability to shell injection attacks is indeed a noteworthy feature of ruby

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane
I saw a wordpress plugin and the wordpress plugin was generating IDs for inputs that had a space in them and it made me cry and it also made baby Jesus cry, so it's just bad all around. Why is wordpress a thing?

spiritual bypass
Feb 19, 2008

Grimey Drawer

PT6A posted:

Why is wordpress a thing?

Because every PHP developer who cares at all about making decent software has stopped using it, leaving only the lovely devs to make plugins. Those lovely ones happen to be the vast majority.

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

xzzy posted:

One of the cleverest (both good and bad types of clever) thing I've seen done with curly braces is in bash, where each pair of curly braces is a subshell. If you string them together with pipes you can create a parallelized event loop.. as subshells produce output the last binary in the pipe reads that and acts upon it.

It's not the curl braces that makes it a subshell, it's the pipes that do. Curly braces just group commands for the purposes of redirection and the like, if you explicitly need a subshell you use parenthesis.

ErIog
Jul 11, 2001

:nsacloud:

rt4 posted:

Because every PHP developer who cares at all about making decent software has stopped using it, leaving only the lovely devs to make plugins. Those lovely ones happen to be the vast majority.

You're forgetting the entire industry of Wordpress plugin malware makers.

qntm
Jun 17, 2009
JavaScript code:
function isBoolean(value) {

    var someBoolean = false;

    if (value){

        if ( _.isBoolean(value) ){
            someBoolean = true;
        }//if
        else if (_.isString(value) ) {
            if ( (value.toLowerCase() === 'true') ||
                 (value.toLowerCase() === 'false')
            ) {
                someBoolean = true;
            }//if
        }//if

    }//if

    return someBoolean;
}

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
edit: misread

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
I'm the //if

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Symbolic Butt posted:

I'm the //if

I'm the unnecessary variable. I'm also the inconsistent use of whitespace.

qntm
Jun 17, 2009
Wow, you folks left it wide open for me, because I'm the function which thinks true is a Boolean but false isn't.

xzzy
Mar 5, 2009

If only javascript had a typeof operator or something, that poor ignorant coder could have avoided being shamed on the internet.

At least partially. I suppose a code base where a boolean could be stored as a string would wind up in here anyways.

brap
Aug 23, 2004

Grimey Drawer
In before everybody starts code golfing on how they'd implement isBoolean in JavaScript

Skyl3lazer
Aug 27, 2007

[Dooting Stealthily]



xzzy posted:

If only javascript had a typeof operator or something, that poor ignorant coder could have avoided being shamed on the internet.

At least partially. I suppose a code base where a boolean could be stored as a string would wind up in here anyways.

I don't think typeof OR isBool are things in javascript. There's a tryparse equivalent for integers but not for Booleans. You actually do need a function similar to this if you want to do it (not that there aren't far more efficient and cleaner ways than shown here)

xzzy
Mar 5, 2009

Skyl3lazer posted:

I don't think typeof OR isBool are things in javascript. There's a tryparse equivalent for integers but not for Booleans. You actually do need a function similar to this if you want to do it (not that there aren't far more efficient and cleaner ways than shown here)

It actually does have typeof, but it's saddled with all the typical javascript baggage where you end up needing to pay special attention if you pass it an object.

qntm
Jun 17, 2009

Skyl3lazer posted:

I don't think typeof OR isBool are things in javascript. There's a tryparse equivalent for integers but not for Booleans. You actually do need a function similar to this if you want to do it (not that there aren't far more efficient and cleaner ways than shown here)

Perhaps a small helper library such as Lodash could provide this, like _.isBoolean! :v:

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
With javascript I can never tell if something is badly written (beyond if (value) in this case...), or if I just don't know javascript well enough for it to be sensable.

Either way it's still badly written I guess.

dougdrums fucked around with this message at 20:23 on Jun 15, 2016

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

xzzy posted:

It actually does have typeof, but it's saddled with all the typical javascript baggage where you end up needing to pay special attention if you pass it an object.

What do you mean? What's wrong with typeof thing === "boolean"?

xzzy
Mar 5, 2009

HappyHippo posted:

What do you mean? What's wrong with typeof thing === "boolean"?

I just was trying to make it clear that if it gets passed anything that is not a primitive type, it'll probably return "object" which would probably confuse newbie developers that didn't read the explanation that just about everything is an object. Like if they pass a string object versus a primitive string.

code:
typeof "abcd"
typeof new String("abcd")
:v:

nielsm
Jun 1, 2009



HappyHippo posted:

What do you mean? What's wrong with typeof thing === "boolean"?

I think the type can be "object", with a class/prototype that is "Boolean". Which is sort of the same but not really.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Right but those sorts of objects are effectively useless as primitives.

code:
var test = new Boolean(false);

if(test) //evaluates to true
	alert("oops!");
  
if(test.valueOf()) //false
	alert("works");
If you have to call "valueOf" on it then your boolean test should probably say that it isn't a boolean, because it sure as gently caress isn't going to act like one.

Carbon dioxide
Oct 9, 2012

I'm not sure what you folks are talking about considering a 'type of' operator.

Java has an instanceof operator, which only works on objects, not on primitives. instanceof returns true if an object is of the given type or extends or implements the given class/interface.

Its main use is to find out if you're allowed to cast an object to a subclass, so you can reach specific subclass methods. Even then, it's often better to just have the subclass method override a method declaration in the superclass/interface.

instanceof does not work on primitives, but that's no problem, because if you try to send the wrong primitive type into a method you'll get a compile error. There's no supertype for primitives, so you'll always know what you're dealing with.

If you try to do arithmetic with primitives, it'll automatically upcast smaller primitive types to the largest used, and integer types to a floating point type. (Also if you do any arithmetic with bytes, shorts, of chars, it'll upcast them to int automatically and you'll have to manually downcast them to the old type if you want to keep it, because the JVM cannot do arithmetic with less than 32 bits). There's no way to directly cast primitive booleans to numeric values or vice versa, booleans are completely their own thing.

String primitives do not exist, String literals automatically become a String object (with as its main member a char array).

At work we often use Integer wrapper objects instead of primitives, because they are allowed to be null.

Carbon dioxide fucked around with this message at 06:07 on Jun 16, 2016

Klades
Sep 8, 2011

I'm just trying to think of what has to go wrong for you to have a spot in your code where a variable could be a boolean or it could be a string representation of a boolean value.


Carbon dioxide posted:

I'm not sure what you folks are talking about considering a 'type of' operator.

Well they're talking about JavaScript for one thing.

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

Klades posted:

I'm just trying to think of what has to go wrong for you to have a spot in your code where a variable could be a boolean or it could be a string representation of a boolean value.


Well they're talking about JavaScript for one thing.

You're talking about JavaScript, so everything already went wrong.

Absurd Alhazred
Mar 27, 2010

by Athanatos

leper khan posted:

You're talking about JavaScript, so everything already went wrong.

New thread title?

pigdog
Apr 23, 2004

by Smythe
Just something I noticed on Stackoverflow sidebar... The struggle is real.

How do I correctly pass the string “Null” (an employee's proper surname) to a SOAP web service from ActionScript 3?

qntm
Jun 17, 2009
JavaScript code:
	 describe('#isBoolean', function () {
	        it('test for boolean values ', function () {
	          
	            var res = validationUtils.isBoolean(false);

	            assert(res  === false, 'Was expecting ==' + false + '. Instead it was ==' + res);
	            
	            res = validationUtils.isBoolean('false');

	            assert(res  === true, 'Was expecting ==' + true + '. Instead it was ==' + res);
	            
	            res = validationUtils.isBoolean(true);

	            assert(res  === true, 'Was expecting ==' + true + '. Instead it was ==' + res);
	            
	            res = validationUtils.isBoolean('true');

	            assert(res  === true, 'Was expecting ==' + true + '. Instead it was ==' + res);
	            
	        });//it
	 });//describe - #isBoolean 

xzzy
Mar 5, 2009

Klades posted:

I'm just trying to think of what has to go wrong for you to have a spot in your code where a variable could be a boolean or it could be a string representation of a boolean value.

Best case, someone inherited a pre-existing project and was trying to make the best of a bad situation.

xtal
Jan 9, 2011

by Fluffdaddy

qntm posted:

Perhaps a small helper library such as Lodash could provide this, like _.isBoolean! :v:

quote:

small library

quote:

Lodash

This is why programming sucks in 2016

Soricidus
Oct 21, 2010
freedom-hating statist shill

Klades posted:

I'm just trying to think of what has to go wrong for you to have a spot in your code where a variable could be a boolean or it could be a string representation of a boolean value.


Well they're talking about JavaScript for one thing.

I think you just answered your own question

evensevenone
May 12, 2001
Glass is a solid.
code:
$ ls deploy/environments
production.ini
looks like it's gonna be one of those days.

necrotic
Aug 2, 2005
I owe my brother big time for this!

xtal posted:

This is why programming sucks in 2016

Lodash publishes individual packages for each function, actually. It's both hilarious and also useful, thanks to the stdlib not existing.

Munkeymon
Aug 14, 2003

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



Minified it's probably smaller than most JPGs before it's compressed for transit and probably already in cache if you use a common CDN URL to load it, so IDK why people think it's some terrible burden.

Polio Vax Scene
Apr 5, 2009



The true horror is being in a situation where you need to check if something is a bool using javascript.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

The real horror is writing code.

raminasi
Jan 25, 2005

a last drink with no ice
Commit message: "Removed obsolete data members"

:suicide:

Skyl3lazer
Aug 27, 2007

[Dooting Stealthily]



raminasi posted:

Commit message: "Removed obsolete data members"

:suicide:

lol he gets that source control is a thing obviously he just doesn't want to let it do its job.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal
C# code:
public ProcessPaymentResult ProcessRecurringPayment(ProcessPaymentRequest processPaymentRequest)
{
    var result = new ProcessPaymentResult();

    var authentication = PopulateMerchantAuthentication();
    if (!processPaymentRequest.IsRecurringPayment)
    {
        ...
    }
}
That's the only thing the parameter does :psyduck:.

Knyteguy fucked around with this message at 00:36 on Jun 17, 2016

Adbot
ADBOT LOVES YOU

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Knyteguy posted:

C# code:
public ProcessPaymentResult ProcessRecurringPayment(ProcessPaymentRequest processPaymentRequest)
{
    var result = new ProcessPaymentResult();

    var authentication = PopulateMerchantAuthentication();
    if (!processPaymentRequest.IsRecurringPayment)
    {
        ...
    }
}
That's the only thing the parameter does :psyduck:.

Maybe more properties from that object used to be referenced.

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