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
Carthag Tuek
Oct 15, 2005

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



Oh dear god

e: Not gonna quote it, let's start this page clean lest its predecessors taint destroy us all

Adbot
ADBOT LOVES YOU

Linear Zoetrope
Nov 28, 2011

A hero must cook

Snapchat A Titty posted:

Oh dear god

e: Not gonna quote it, let's start this page clean lest its predecessors taint destroy us all

Nonsense, we need more enterprise quality code in this thread.

https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

Carthag Tuek
Oct 15, 2005

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



Jsor posted:

Nonsense, we need more enterprise quality code in this thread.

https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

Depressingly, it's one of the most healthy repos I've seen, fork/pullrequest-wise. Lots of new stuff getting merged in.



I guess at the very least it proves that bikeshedding can be a motivating factor.

pmchem
Jan 22, 2010


Jsor posted:

Julia auto-promotes ints to floats for division, but there is a special operator for integer division. It seems to work pretty well there, but then Julia is also a scientific computing language.

I imagine that style of handling division was borrowed from Python 3? Because P3 does the same thing, and Julia devs are quite aware of their main competition.

Pavlov
Oct 21, 2012

I've long been fascinated with how the alt-right develops elaborate and obscure dog whistles to try to communicate their meaning without having to say it out loud
Stepan Andreyevich Bandera being the most prominent example of that

pmchem posted:

I imagine that style of handling division was borrowed from Python 3? Because P3 does the same thing, and Julia devs are quite aware of their main competition.

Enough so that one of the libraries lets you write @pyimport whatever and you essentially just use the imported python library like normal. Python's biggest strength is probably its libraries so its really convenient. I wish I had more of an excuse to use it.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

Qwertycoatl posted:

code:
unsigned int is_even(unsigned int x)
{
    for (unsigned int i = 0; i < x; i++) {
        x *= x;
    }
    return !x;
}

That is really amazing

TheresaJayne
Jul 1, 2011

canis minor posted:

My next favourite thing, after JS/Java, is - "Have you programmed in MVC? How many applications have you written in MVC?"

(it might be pedantic, but MVC is not a programming language, goddamit)

The one i always annoy agents with are when the conversation goes like this
they ask "can you write J2EE, - Yes 12 years now since J2EE 1.0"
Have you ever used Java - Yes 12 years now since J2EE 1.0 and Java 1.4.2
So what about javac have you any experience in that?

At that point i usually explode and explain that if you use J2EE that is just a special type of java object but you are still writing java code, and javac is the compiler for java.

They then go "oh, right so anything to do with java you have done" - Yes - "and so that means you know Coldfusion then " - cue Explosion 2..

I hate recruiters who don't know their subject.

TheresaJayne fucked around with this message at 11:28 on May 15, 2015

Slash
Apr 7, 2011

TheresaJayne posted:

Queue Explosion 2..

cue...

QuarkJets
Sep 8, 2008

Pavlov posted:

Is numba any good? I feel like it's trying to do something to python that python just wasn't built to do.

It's basically Julia but uses Python syntax and is a lot easier to use. It has plenty of room for improvement but it's already an awesome module if you're doing computational math or science

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

"Convenient proxy factory bean superclass for proxy factory beans that create only singletons."

Well duh, it's right there in the name.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

zergstain posted:

I love how that will overflow if n is odd.

It's like a turing machine. You can't return false. You either return true or loop forever.

Linear Zoetrope
Nov 28, 2011

A hero must cook

Dr. Stab posted:

It's like a turing machine. You can't return false. You either return true or loop forever.

Huh? TMs can reject, you're thinking of Turing-recognizable (as opposed to decidable) languages. And even those can reject, they're just not guaranteed to.

Meat Beat Agent
Aug 5, 2007

felonious assault with a sproinging boner
http://stackoverflow.com/questions/30262509/union-object-acts-like-a-structure

Vanadium
Jan 8, 2005

Programmers hate unions. :laugh:

return0
Apr 11, 2007

Qwertycoatl posted:

code:
unsigned int is_even(unsigned int x)
{
    for (unsigned int i = 0; i < x; i++) {
        x *= x;
    }
    return !x;
}

whoa, why does this work

Qwertycoatl
Dec 31, 2008

return0 posted:

whoa, why does this work

It relies on integer overflow. If you repeatedly square an even number, it will become 0 mod 2^32. If you repeatedly square an odd number, it will become 1 mod 2^32. When one of those things happens, the for loop will terminate and the answer will come out.

return0
Apr 11, 2007

Qwertycoatl posted:

It relies on integer overflow. If you repeatedly square an even number, it will become 0 mod 2^32. If you repeatedly square an odd number, it will become 1 mod 2^32.

:O

crazypenguin
Mar 9, 2005
nothing witty here, move along

Qwertycoatl posted:

It relies on integer overflow. If you repeatedly square an even number, it will become 0 mod 2^32. If you repeatedly square an odd number, it will become 1 mod 2^32. When one of those things happens, the for loop will terminate and the answer will come out.

It also relies on re-evaluation of x in the conditional. Otherwise it'd report false for 2.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Jsor posted:

Huh? TMs can reject, you're thinking of Turing-recognizable (as opposed to decidable) languages. And even those can reject, they're just not guaranteed to.

Languages don't reject or loop or really do anything. Also, TMs can be defined to have a reject state, but typically, in my experience, aren't.

Mellow_
Sep 13, 2010

:frog:

Holy poo poo this is amazing. What would drive someone to do such a thing?

sarehu
Apr 20, 2007

(call/cc call/cc)
Rejecting states are just all the states that aren't accepting states. If the machine halts and does not accept, that's rejection.

Linear Zoetrope
Nov 28, 2011

A hero must cook

sarehu posted:

Rejecting states are just all the states that aren't accepting states. If the machine halts and does not accept, that's rejection.

Yes

Dr. Stab posted:

Languages don't reject or loop or really do anything. Also, TMs can be defined to have a reject state, but typically, in my experience, aren't.

"(Turing-)Decidable languages" is, by definition, languages that a Turing Machine can accept or reject in finite time. Above that is recognizable (or undecidable), which contains things like the accepting or halting problem which always accept in finite time if an answer exists, but may or may not halt if one doesn't exist.

In the Theory of Computation, you frequently deal with Turing Machines that don't halt, Complexity Theory is basically all about Turing Machines that accept or reject in finite time. In fact, the "witness" definition of coNP* is usually defined in terms of rejection.

* L is in coNP if L can be represented as { x | forall w, M(x,w) rejects }

Linear Zoetrope fucked around with this message at 02:57 on May 16, 2015

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

sarehu posted:

Rejecting states are just all the states that aren't accepting states. If the machine halts and does not accept, that's rejection.

Sorry, what definition are you using? I'm unaware of one which specifies halting in the transition function and not the state space. Typically, turing machines that reject have explicit reject states, and halt immediately upon entering such a state. The behaviour you're describing is more in line with how lower-order automata are defined, where they check which state they are in once they reach the end of input.

Jsor posted:

"(Turing-)Decidable languages" is, by definition, languages that a Turing Machine can accept or reject in finite time. Above that is undecidable, which contains things like the accepting or halting problem which always accept in finite time if an answer exists, but may or may not halt if one doesn't exist.

In the Theory of Computation, you frequently deal with Turing Machines that don't halt, Complexity Theory is basically all about Turing Machines that accept or reject in finite time. In fact, the "witness" definition of coNP* is usually defined in terms of rejection.

* L is in coNP if L can be represented as { x | forall w, M(x,w) rejects }

I'm not saying that there don't exist turing machines that reject. It would be like if you showed me a space complexity result that relied on multi-tape turing machines to tell me that my assertion that turing machines typically have 1 tape is wrong.

Dr. Stab fucked around with this message at 02:57 on May 16, 2015

Linear Zoetrope
Nov 28, 2011

A hero must cook
I suppose I concede that you could have a Turing Machine with no rejection, but we usually talk about TMs in relation to decision problems, which specify determining the truth or falsity of a statement. Indeed, Turing's original paper was all about applying the automatic machine to the Entscheidungsproblem. I'd say the vast majority of the time, TMs reject, but I'll agree that it's not strictly necessary if you were solving an optimization problem.

VikingofRock
Aug 24, 2008




Qwertycoatl posted:

code:
unsigned int is_even(unsigned int x)
{
    for (unsigned int i = 0; i < x; i++) {
        x *= x;
    }
    return !x;
}

Qwertycoatl posted:

It relies on integer overflow. If you repeatedly square an even number, it will become 0 mod 2^32. If you repeatedly square an odd number, it will become 1 mod 2^32. When one of those things happens, the for loop will terminate and the answer will come out.

I'm still a little surprised that it works for every number less than 2^32 (although it does--I checked). The loop terminates whenever i>=x, and some numbers wrap around a bunch of times. What's to say that an even x never wraps around to a number greater than 1 but less than i?

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

VikingofRock posted:

I'm still a little surprised that it works for every number less than 2^32 (although it does--I checked). The loop terminates whenever i>=x, and some numbers wrap around a bunch of times. What's to say that an even x never wraps around to a number greater than 1 but less than i?

Because every time you square a number, you're doubling the zeros at the end of the number. Like, if you take 10 and square it, the result is 100. 100 squared is 10000. So, if you start with a number ending in 0 and square it and it wraps around, the result is either 0 or greater than 3. But, if i is greater than 3, then that means that you've done at least 5 multiplications, in which case the number would have to have at least 32 trailing zeroes.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

VikingofRock posted:

I'm still a little surprised that it works for every number less than 2^32 (although it does--I checked). The loop terminates whenever i>=x, and some numbers wrap around a bunch of times. What's to say that an even x never wraps around to a number greater than 1 but less than i?

Unsigned multiplication can never result in a number less than the product of the lowest bits in each number unless it overflows to zero. If x starts off non-zero but even, the value of its lowest bit grows super-exponentially (x2i). Meanwhile i grows linearly.

There's a similar interesting thing that happens when squaring odd numbers; consider the expansion of (a*2k+1)2.

VikingofRock
Aug 24, 2008




Ah okay, I'm happy with those explanations. Thanks guys!

Mellow_
Sep 13, 2010

:frog:
php:
<?

foreach($cite as $site){
        $length = strpos($cite[$i], "</cite>");
        $positions[$i] = substr($cite[$i], 0, $length); 
        $post[$i] = strip_tags($positions[$i]);
        if(strpos($post[$i],$domain) !== false){
            $link = $i;
            break;
        }
        $i++;
    }
    // Provide More Information to the User
    $overall = $link-1;
    $number = ($link/10)+1;
    $number = floor($number);
    $math = strlen($link);
    $result = substr($link, $math-1, 1); 
    
    $encoded = base64_encode($information);
    $filename = substr($encoded, 0, 5);
    $file = "demos/".$filename.".txt";
    file_put_contents($file, $encoded);
    if($overall == -1){
        $number = 0;
        $result = 0;
    }

?>
:psyduck:

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

Munkeymon posted:

Try that with 2147483648 (231) in JS.

code:
alert(2147483648 << 0);
code:
-2147483648
loving javascript man

Edit: But now I can fix my even test!
code:
function isEven(n) {
    return (n >> 1 << 1) == (n >> 0 << 0);
}

HappyHippo fucked around with this message at 15:53 on May 16, 2015

TheresaJayne
Jul 1, 2011

Vanadium posted:

Programmers hate unions. :laugh:

Is that why most of them are single? .. or virgins ... or both

Look Around You
Jan 19, 2009

TheresaJayne posted:

Is that why most of them are single? .. or virgins ... or both

also because gently caress workers rights amirite :911:

IT BEGINS
Jan 15, 2009

I don't know how to make analogies
php:
<?
if (-- some long conditional here -- && false) {
    ... bunch of poo poo ...
   exit(0);
}
?>
Lovely. Here I am, hunting for why I'm not falling out, and it turns out I've been looking at a conditional that will never evaluate. Should have just gone into the debugger immediately, would have saved me an hour or so.

Hughlander
May 11, 2005

IT BEGINS posted:

php:
<?
if (-- some long conditional here -- && false) {    ... bunch of poo poo ...   exit(0);}?>

Lovely. Here I am, hunting for why I'm not falling out, and it turns out I've been looking at a conditional that will never evaluate. Should have just gone into the debugger immediately, would have saved me an hour or so.

To be fair the conditional should evaluate. It's just the result will always be false right? PHP doesn't optimize out the rest I hope.

IT BEGINS
Jan 15, 2009

I don't know how to make analogies

Hughlander posted:

To be fair the conditional should evaluate. It's just the result will always be false right? PHP doesn't optimize out the rest I hope.

Yeah, this thing is equivalent to if (false) . If the stuff in the conditional executed something that would be fine, but this is all just one big lovely if nothing.

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

IT BEGINS posted:

Yeah, this thing is equivalent to if (false) . If the stuff in the conditional executed something that would be fine, but this is all just one big lovely if nothing.

Err... PHP does not magic away the stuff before the && false... http://sandbox.onlinephpfunctions.com/code/4722935a6f2853756b11b31b2b60676f098d2492

IT BEGINS
Jan 15, 2009

I don't know how to make analogies
Yes, I know. I'm just saying that there's nothing in there in this particular case that does anything, just straight == comparisons between variables.

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

IT BEGINS posted:

Yes, I know. I'm just saying that there's nothing in there in this particular case that does anything, just straight == comparisons between variables.

Gotcha.

Space Whale
Nov 6, 2014
This was written this year.

Why would you build a string in SQL then execute the string in a stored procedure?
code:
ALTER PROCEDURE [dbo].[pr_VMGetListFOOInformation]
	@FOOName NVARCHAR(40)
,	@FOOCity NVARCHAR(40)
,	@FOOState NVARCHAR(40)
,	@FOOCountry NVARCHAR(40)
,   @FOOSupergroup NVARCHAR(40)
,   @FOOParent NVARCHAR(40)

AS
BEGIN
	 DECLARE

		@Select_Stmt NVARCHAR(1000) = NULL,
		@Where_Stmt NVARCHAR(1000) = NULL,
		@Full_Statement NVARCHAR(2000) = NULL

	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	SET FMTONLY OFF;

	SET @Select_Stmt = ' SELECT v.FOOID, v.FOOName, v.BARID, va.City, venStatus.Description AS Status, va.CountryID, spl.Description AS State, cpl.Description AS Country, 
spl.StateID, venSup.Description AS Supergroup, venPar.ParentName AS Parent' 
    SET @Select_Stmt = @Select_Stmt + ' FROM [dbo].[FOO] AS v'
	SET @Select_Stmt = @Select_Stmt + ' LEFT OUTER JOIN [dbo].[FOOAddress] AS va ON v.FOOID = va.FOOID' 
	SET @Select_Stmt = @Select_Stmt + ' LEFT OUTER JOIN [dbo].[StatePL] AS spl ON va.StateID = spl.StateID'
	SET @Select_Stmt = @Select_Stmt + ' LEFT OUTER JOIN [dbo].[CountryPL] AS cpl ON cpl.CountryID = va.CountryID' 
	SET @Select_Stmt = @Select_Stmt + ' LEFT OUTER JOIN [dbo].[FOOStatusPL] AS venStatus ON venStatus.FOOStatusID = v.FOOStatusID' 
	SET @Select_Stmt = @Select_Stmt + ' LEFT OUTER JOIN [dbo].[FOOSupergroupPL] AS venSup ON venSup.FOOSupergroupID = v.FOOSupergroupID' 
	SET @Select_Stmt = @Select_Stmt + ' LEFT OUTER JOIN [dbo].[ParentPL] AS venPar ON venPar.ParentID = v.ParentID' 
	    /*Building where clause statement*/

	SET @Where_Stmt = ' WHERE 1=1'
    
    IF @FOOName IS NOT NULL
		BEGIN			
			SET @Where_Stmt = @Where_Stmt + ' AND v.FOOName LIKE '''+ '%' + @FOOName + '%' + '''' 
		END		
	IF @FOOCity IS NOT NULL
		BEGIN
			SET @Where_Stmt = @Where_Stmt + ' AND va.City LIKE '''+ '%' + @FOOCity + '%' + ''''   
		END
	IF @FOOState IS NOT NULL
		BEGIN
			SET @Where_Stmt = @Where_Stmt + ' AND spl.StateID = ' + @FOOState 
		END
	IF @FOOCountry IS NOT NULL
		BEGIN
			SET @Where_Stmt = @Where_Stmt + ' AND cpl.CountryID = ' + @FOOCountry 
		END
	IF @FOOSupergroup IS NOT NULL
		BEGIN
			SET @Where_Stmt = @Where_Stmt + ' AND venSup.FOOSupergroupID = ' + @FOOSupergroup
		END
	IF @FOOParent IS NOT NULL
		BEGIN
			SET @Where_Stmt = @Where_Stmt + ' AND venPar.ParentID = ' + @FOOParent
		END

	SET @Where_Stmt = @Where_Stmt + ' AND (va.FOOAddressTypeID = 1 OR va.FOOAddressTypeID IS NULL)'
    
	   /*Building where full statement*/   
   SET @Full_Statement = @Select_Stmt + ISNULL(@Where_Stmt,'')    
   PRINT @Full_Statement
   EXEC sp_executesql @Full_Statement 

Adbot
ADBOT LOVES YOU

MrMoo
Sep 14, 2000

That's pretty standard fare in enterprise apps, I frequently see that inside a gigantic SQL call instead of a stored proc though. I call it commodity coding.

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