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
ToxicFrog
Apr 26, 2008


leterip posted:

So (2 > 1 is True) evaluates to (2 > 1 and 1 is True) which is False. The parenthesis stop the expansion. (This one took me a while to figure out.)

Here's the bit that confuses me:
code:
>>> 2 > (1 is True)
True
Wait, what?

code:
>>> 1 is True
False
>>> 2 > False
True
Is False getting coerced to 0 there or something?

Adbot
ADBOT LOVES YOU

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

ToxicFrog posted:

Here's the bit that confuses me:
code:
>>> 2 > (1 is True)
True
Wait, what?

code:
>>> 1 is True
False
>>> 2 > False
True
Is False getting coerced to 0 there or something?

Yes, False == 0. I'll repeat myself from the previous page:
code:
>>> None < False == 0 < True == 1 < {} < [] < '' < '0' < ()
True
You can compare all sorts of stuff, and not all of it makes sense. Sets Tuples are greater than strings are greater than lists are greater than dictionaries are greater than numbers. 1 is True and 0 is False. None is the smallest thing there is.

LOOK I AM A TURTLE fucked around with this message at 07:15 on Jan 20, 2012

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
More Python 3 :smug:-ness

code:
Python 3.2.2+ (default, Dec 19 2011, 12:03:32) 
[GCC 4.6.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> None < False == 0 < True == 1 < {} < [] < '' < '0' < ()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: NoneType() < bool()
It looks like booleans are still implicitly converted to ints though:
code:
>>> 2 > False
True
>>> True + 3j
(1+3j)
There wasn't a boolean type in the language until 2.3 -- True and False were added in 2.2.1 but were just different names for 1 and 0 (look here for details).

Hell, until 3+, you could assign to True and False:
code:
Python 2.7.2+ (default, Jan  7 2012, 07:34:05) 
[GCC 4.6.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> True = []
>>> True.append('butts')
>>> True
['butts']
I don't have any 3.0 or 3.1 installations handy, but that raises a SyntaxError in 3.2.

EDIT: Looks like this was a 3.0 thing: http://docs.python.org/py3k/whatsnew/3.0.html#changed-syntax

Lysidas fucked around with this message at 03:17 on Jan 20, 2012

Carthag Tuek
Oct 15, 2005

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



Here's one from myself (not actually a coding horror but a case of severe retardation):

code:
    NSPoint origin = NSMakePoint(fmin(startPoint.x, endPoint.x), fmin(startPoint.y, endPoint.y));
    NSPoint end = NSMakePoint(fmax(startPoint.x, endPoint.x), fmax(startPoint.y, endPoint.y));
    NSSize size = NSMakeSize(end.x - origin.x, end.y - origin.y);
    
    NSRect rect = NSMakeRect(origin.x, origin.y, size.width, size.height);

    NSRect convertedRect = [self convertRect:rect fromView:[[self window] contentView]];
I just spent over 20 minutes agonizing over why the size of convertedRect was identical to the size of the original rect :downs:

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.
Oh god. I just found this in some code I wrote... almost exactly 4 years ago, if the date stamp in the comments is to be believed.

In my defence, it was an internal application, and it had to pass auth checks before it could get near this code. That's a poor defence, but there you have it.

I was young and stupid?

php:
<?
// validate editable fields
$editable_fields = array("customerid"=>"is_int", 
                         "project"=>"is_string", 
                         "fixedquote"=>"is_string", 
                         "quoteamount"=>"is_numeric",
                         "quotehours"=>"is_int", 
                         "active"=>"is_int");

// is it an editable field?
if (isset($editable_fields[$_POST['field']])) {
    // is the value valid?
    if (eval("return ".$editable_fields[$_POST['field']]."('".addslashes($_POST['value'])."');")) {
        /* ... do stuff ... */
    } else {
        /* error about not being the right type of data */
    }
} else {
    /* error about not being an editable field */
}
Obviously, my intention was to make a very simple api which let me edit/change certain fields in a table without having to write too much specialised validation code.

I'm going through and replacing it with this, which is still a horror in it's own right, but less of one.

php:
<?
if (isset($editable_fields[$_POST['field']])) {
    $func = $editable_fields[$_POST['field']];
    // is the value valid?
    if ($$func($_POST['value'])) {
        /* ... do stuff ... */
    } else {
        /* error about not being the right type of data */
    }
} else {
    /* error about not being an editable field */
}

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
I haven't done one of these in a while: multi-threaded FizzBuzz.

code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace MultiThreadedFizzBuzz
{
    class MultiThreads
    {
        public void StartAll()
        {
            Thread numThread = new Thread(RunInts);
            Thread fizzThread = new Thread(RunFizz);
            Thread buzzThread = new Thread(RunBuzz);
            Thread fizzBuzzThread = new Thread(RunFizzBuzz);
            numThread.Start();
            Thread.Sleep(200);  //Dark magic.
            fizzThread.Start();
            buzzThread.Start();
            fizzBuzzThread.Start();
        }

        private volatile int i = 1;

        private object LockObject = new object();

        private object FizzObject = new object();

        private object BuzzObject = new object();

        private object FizzBuzzObject = new object();

        public void RunInts()
        {
            lock (FizzObject)
            {
                lock (BuzzObject)
                {
                    lock (FizzBuzzObject)
                    {
                        while (i <= 100)
                        {
                            if (i % 15 == 0)
                            {
                                Monitor.PulseAll(FizzBuzzObject);
                                Monitor.Wait(FizzBuzzObject);
                            }
                            else if (i % 3 == 0)
                            {
                                Monitor.PulseAll(FizzObject);
                                Monitor.Wait(FizzObject);
                            }
                            else if (i % 5 == 0)
                            {
                                Monitor.PulseAll(BuzzObject);
                                Monitor.Wait(BuzzObject);
                            }
                            else
                            {
                                Console.WriteLine(i);
                            }
                            i++;
                        }
                    }
                }
            }
        }

        public void RunFizz()
        {
            lock (FizzObject)
            {
                while (i <= 100)
                {
                    Console.WriteLine("Fizz");
                    Monitor.PulseAll(FizzObject);
                    Monitor.Wait(FizzObject);
                }
            }
        }

        public void RunBuzz()
        {
            lock (BuzzObject)
            {
                while (i <= 100)
                {
                    Console.WriteLine("Buzz");
                    Monitor.PulseAll(BuzzObject);
                    Monitor.Wait(BuzzObject);
                }
            }
        }

        public void RunFizzBuzz()
        {
            lock (FizzBuzzObject)
            {
                while (i <= 100)
                {
                    Console.WriteLine("FizzBuzz");
                    Monitor.PulseAll(FizzBuzzObject);
                    Monitor.Wait(FizzBuzzObject);
                }
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var m = new MultiThreads();
            m.StartAll();
            Console.ReadLine();
        }
    }

}

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
This might be a repeat but python chat reminded me of my favourite python thing:

code:
% python
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
YOU KNOW WHAT I WANT TO DO HOW IS THIS HELPFUL

pseudorandom name
May 6, 2007

The python repl is geared towards learning the language, and "exit" isn't a function call.

Opinion Haver
Apr 9, 2007

Haha, apparently by default exit is bound to a Quitter object whose __repr__ is that 'Use exit()' message.

Carthag Tuek
Oct 15, 2005

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



yaoi prophet posted:

Haha, apparently by default exit is bound to a Quitter object whose __repr__ is that 'Use exit()' message.

Honestly when it's put like that, I gotta go with pokeyman. Python is being a dick right there. And lord knows I've typed exit so many times.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
I forget which but one of the calculator programs (dc or bc) is worse. It traps C-c and yells at you to use exit() instead

Impotence
Nov 8, 2010
Lipstick Apathy
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
^C
(interrupt) use quit to exit.

Opinion Haver
Apr 9, 2007

See, I figure that's because they wanted C-c to kill a long-running computation but not have mashing C-c get rid of all of your saved state.

Carthag Tuek
Oct 15, 2005

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



ctrl Z
kill %1

You're not my dad, don't tell me what I can and cannot do

ToxicFrog
Apr 26, 2008


yaoi prophet posted:

See, I figure that's because they wanted C-c to kill a long-running computation but not have mashing C-c get rid of all of your saved state.

Yeah, that's an entirely reasonable approach.

Vanadium
Jan 8, 2005

vim and nethack also catch C-c, those bastards. :colbert:

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
I need a custom keyboard so that I can bind C-"NO YOU SHUT THE gently caress UP DAD" to SIGKILL

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Otto Skorzeny posted:

I need a custom keyboard so that I can bind C-"NO YOU SHUT THE gently caress UP DAD" to SIGKILL
ctrl-\ is pretty close (SIGQUIT)

Suspicious Dish
Sep 24, 2011

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

yaoi prophet posted:

Haha, apparently by default exit is bound to a Quitter object whose __repr__ is that 'Use exit()' message.

Right. The reason it doesn't just quit on __repr__ is because anything that calls repr() on it will quit the program. There are quite a few tools in the stdlib that do, so using those tools on the global scope shouldn't just abort randomly.

McGlockenshire
Dec 16, 2005

GOLLOCKS!

bobthecheese posted:

I'm going through and replacing it with this, which is still a horror in it's own right, but less of one.

php:
<?
if (isset($editable_fields[$_POST['field']])) {
    $func = $editable_fields[$_POST['field']];
    // is the value valid?
    if ($$func($_POST['value'])) {
        /* ... do stuff ... */
    } else {
        /* error about not being the right type of data */
    }
} else {
    /* error about not being an editable field */
}

You should probably just do:
php:
<?
if(array_key_exists($_POST['field'], $editable_fields) && function_exists($editable_fields[ $_POST['field'] ])) {
    if($editable_fields[$_POST['field']]($_POST['value'])) {
    // ...
    }
}?>
No need for the temporary variable or the double dollar. Checking that the key exists is more explicit than the isset, and checking that the function exists is a good typo check.

It's still a coding horror, but so is PHP.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Move over AES and PGP, it's time for "The most secure data cryption program in the world": KRYPTOChef!

AES and PGP are public algorithms, which means that anybody can study them to learn how they work and decrypt any file. KRYPTOChef is different:

KRYPTOChef posted:

It will be a self-developed by me (ONLY) in KRYPTO used (OTP encryption method) is used.
KRYPTO can neither humans or computers, without the right key or password unauthorized to decrypt.
The access to the program itself KRYPTO via username and password in the highest depth protected encryption.
KRYPTO one of the world, the most secure data encryption programs. It is time the world is not a safe data
cryption program as KRYPTO which is offered anywhere.
KRYPTO is absolutely secure against unauthorized data decryption.

It even has proof of its security! Watch:

KRYPTOChef posted:

Proof of the Krypto security !
Which would be, if one would try one of Krypto coded file unauthorized to decode.
A coded file with the length of 18033 indications has therefore according to computation,
256 bits highly 18033 indications = 6,184355814363201353319227173630E+43427 file possibilities.
Each file possibility has exactly 18033 indications byte.
Multiplied by the number of file possibilities then need results in the memory.
Those are then: 1,1152248840041161000440562362208e+43432 byte.
Those are then: 1,038634110245961789082788150963è+43423 Giga byte data quantity.
That is a number with 43424 places.
I can surely maintain as much memory place give it in the whole world not never.
And the head problem now is, which is now the correctly decoded file.
Who it does not know can only say there. That does not know so exactly !

For those not versed in idiot, this says: "The permutation of files with 18,033 bytes is a number with over 43,424 places."

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Suspicious Dish posted:

Move over AES and PGP, it's time for "The most secure data cryption program in the world": KRYPTOChef!

AES and PGP are public algorithms, which means that anybody can study them to learn how they work and decrypt any file. KRYPTOChef is different:


It even has proof of its security! Watch:


For those not versed in idiot, this says: "The permutation of files with 18,033 bytes is a number with over 43,424 places."

In a million years, whatever humans have evolved to will have this inscribed on their buildings / on their currency:

some sort of crazy posted:

Who it does not know can only say there. That does not know so exactly !

Zhentar
Sep 28, 2003

Brilliant Master Genius
I can't imagine why you picked those two excerpts when this was sitting between them

KRYPTOchef posted:

Why are 256 bits the technically highest coding depth at all on computers possible are ?
A computer knows only 256 different indications.
1 indication = 1 byte has 8 bits in binary the number system exactly.
1 bit knows only the switching status: on or out or 0 or 1 by the combination of these 8 bits results 256 bits.
The computation in addition: 2 switching status highly 8 bits = 256 bits
these 256 bits is addressed in decimally the number system from 0 to 255 = 256 bits.
Computers work however in in hexadecimals the number system.
There these 256 bits designated above are addressed from 00 to FF = 256 bits.
A byte cannot be thus under bits 0 or over bits 255.
Therefore 256 bits are the technically highest coding depth at all on computers possible are.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
Pretty sure he's crazy. The newsletter is a rant about some judge violating his human rights, and demands 2mil EUR from the German chancellor.

Also if he gets 2mil EUR in donations he'll release the program for free to everyone.

Look Around You
Jan 19, 2009

Aleksei Vasiliev posted:

Pretty sure he's crazy. The newsletter is a rant about some judge violating his human rights, and demands 2mil EUR from the German chancellor.

Also if he gets 2mil EUR in donations he'll release the program for free to everyone.

Can we send him a huge rear end fake €2,000,000 note so that he publishes it or would that be illegal/immoral?

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

McGlockenshire posted:

You should probably just do:
php:
<?
if(array_key_exists($_POST['field'], $editable_fields) && function_exists($editable_fields[ $_POST['field'] ])) {
    if($editable_fields[$_POST['field']]($_POST['value'])) {
    // ...
    }
}?>
No need for the temporary variable or the double dollar. Checking that the key exists is more explicit than the isset, and checking that the function exists is a good typo check.

It's still a coding horror, but so is PHP.

Could probably also use call_user_func_array() for slightly cleaner code.

php:
<?
call_user_func_array($editable_fields[$_POST['field']], array($_POST['value']));?>

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Look Around You posted:

Can we send him a huge rear end fake €2,000,000 note so that he publishes it or would that be illegal/immoral?

Send him an encrypted string, say it's a swiss bank account number w/ PIN that has 2 million euro in it. Since he's a crypto genius he should be able to crack it.

FLEXBONER
Apr 27, 2009

Esto es un infierno. Estoy en el infierno.
Here's a lightning talk about why JavaScript sucks (and a few things about Ruby, too) that sheds more light on why JavaScript is an awful, awful language.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Oh, it's not an awful language. In fact, it's not a language at all. :smuggo:

xf86enodev
Mar 27, 2010

dis catte!

Poop Delicatessen posted:

Here's a lightning talk about why JavaScript sucks (and a few things about Ruby, too) that sheds more light on why JavaScript is an awful, awful language.

That was like watching an old episode of Roseanne.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Poop Delicatessen posted:

Here's a lightning talk about why JavaScript sucks (and a few things about Ruby, too) that sheds more light on why JavaScript is an awful, awful language.

JavaScript has some rough parts, and that's why I'm becoming a huge fan of CoffeeScript. Plus, I just really like CoffeeScript's syntax over JavaScript.

Look Around You
Jan 19, 2009

Doc Hawkins posted:

Oh, it's not an awful language. In fact, it's not a language at all. :smuggo:

What the gently caress is this poo poo? Like I honestly have no idea how he's saying that a turing complete language that's actually pretty powerful despite having a simple syntax isn't a language.

this dumbfuck posted:

Years ago I read something which explained, in my opinion, why Lisp has never achieved the mainstream adoption its passionate advocates believe it deserves. Lisp projects experience a degree of balkanization because everything is left wide open; you can use more than one object-oriented paradigm (potentially even at the same time), you write your own this, you write your own that, you write your own everything.

I don't know any extremely popular languages which provide a few simple but powerful constructs. Wait, Lua is pretty widespread and it has no built in OO system. I just :psyduck:

e:
I mean lisp definitely isn't mainstream probably because it's not the most readable thing ever (and because most people aren't 100% comfortable with functional programming), but that certainly doesn't mean it's not a powerful programming language.

Look Around You fucked around with this message at 03:38 on Jan 24, 2012

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Look Around You posted:

What the gently caress is this poo poo? Like I honestly have no idea how he's saying that a turing complete language that's actually pretty powerful despite having a simple syntax isn't a language.


It's even worse because he basically takes a Douglas Crockford's "Javascript is Lisp in C's clothing" and deranges it beyond reason. He then goes on to claim that Lisp is simply for AST manipulation and really isn't abstract enough to handle pragmatic programming.

I haven't seen such a stupid hunk of poo poo since I watched some talk where the guy called Barbara Liskov a "dude"

Look Around You
Jan 19, 2009

TRex EaterofCars posted:

It's even worse because he basically takes a Douglas Crockford's "Javascript is Lisp in C's clothing" and deranges it beyond reason. He then goes on to claim that Lisp is simply for AST manipulation and really isn't abstract enough to handle pragmatic programming.

I haven't seen such a stupid hunk of poo poo since I watched some talk where the guy called Barbara Liskov a "dude"

Yeah I saw that and shut my brain off because I couldn't comprehend just how loving stupid this guy is. Like jesus christ.

e:
I mean the least insane point he has I guess is the "it lacks some built in stuff" but that doesn't really keep a language from being a language. Just loving christ that guy.

Look Around You fucked around with this message at 04:33 on Jan 24, 2012

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Look Around You posted:

I don't know any extremely popular languages which provide a few simple but powerful constructs. Wait, Lua is pretty widespread and it has no built in OO system. I just :psyduck:
Lua has syntax and features explicitly intended for prototype-based OOP.

TRex EaterofCars posted:

He then goes on to claim that Lisp is simply for AST manipulation and really isn't abstract enough to handle pragmatic programming.
He's basically saying the same thing as all the people who talk about how awesome Lisp is because you can easily create a DSL and then write your program in that... which is a pretty widely accepted way to use Lisp (to the extent that anything involving Lisp can be called "widely accepted").

Extending this idea to Javascript is pretty dumb though, as Javascript doesn't give you any tools for creating your own language that you write your actual program in.

Plorkyeran fucked around with this message at 04:35 on Jan 24, 2012

Look Around You
Jan 19, 2009

Plorkyeran posted:

Lua has syntax and features explicitly intended for prototype-based OOP.

Yeah but I mean so does Javascript.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Look Around You posted:

Yeah but I mean so does Javascript.

And Lisp doesn't, which is what he was talking about there.

Lua also has a decent module system.

It's actually sort of pathetic that there are so many high-level languages which don't have features which Lua has.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Plorkyeran posted:

He's basically saying the same thing as all the people who talk about how awesome Lisp is because you can easily create a DSL and then write your program in that... which is a pretty widely accepted way to use Lisp (to the extent that anything involving Lisp can be called "widely accepted").

If that's really what he is saying he chose a lovely way to say it. Cause to me it seemed like he was saying Lisp isn't pragmatic for programming anything beyond fiddling with syntax trees. In fact that's exactly what he said.

Look Around You
Jan 19, 2009

Plorkyeran posted:

And Lisp doesn't, which is what he was talking about there.

Lua also has a decent module system.

It's actually sort of pathetic that there are so many high-level languages which don't have features which Lua has.

Common Lisp also has CLOS as part of its ANSI standard. And honestly you don't absolutely need objects in a functional language.

Adbot
ADBOT LOVES YOU

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


TRex EaterofCars posted:

If that's really what he is saying he chose a lovely way to say it.

I dunno about that. After all, here we are, reacting to it.

The line between branding and trolling can become quite thin in the celebrity-developer world.

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