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
Linear Zoetrope
Nov 28, 2011

A hero must cook
Not programming so much as CS, but I just realized that on a test I wrote

if not (a ⊕ b)

for boolean values !(a xor b) is just a==b

Adbot
ADBOT LOVES YOU

sarehu
Apr 20, 2007

(call/cc call/cc)
Oh yeah that's a classic, !(a ^ b) is something I've argued about in a code review.

Scaevolus
Apr 16, 2007

code:
var commandProbability = 0.03; //This is actually ~2% because Math.random doesn't include 1.0
var commandThreshold = Math.random() + commandProbability;

if (commandThreshold > 1) {

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
My mental image is something like a dude on a skateboard, going "Oh my god, I think I finally got this, you gu-" and then faceplanting right into some stairs.

TheresaJayne
Jul 1, 2011

Dessert Rose posted:

My mental image is something like a dude on a skateboard, going "Oh my god, I think I finally got this, you gu-" and then faceplanting right into some stairs.

that gave me the image of this :::
https://youtu.be/olit-B5Yldc?t=35s

IT BEGINS
Jan 15, 2009

I don't know how to make analogies
If you ever wanted to see a God Object, here's a great example. I've omitted the rest to anonymize it a bit (and also for sanity).

php:
<?php
include_once "dashhelpers.php";
class Dashboard extends \main{
    public $buffer false;
    public $metricClass = array();
    
    function __construct(&$post) {
        global $main$userid;
        
         // more omitted for sanity
        
        if($post['event'] ==="promptQuestion"){
            $this->run("createPrompt");
             echo json_encode(array(
                 prompt => $this->promptMessage
             ));
            exit(1);

        }
        if($post['event']==="savePrefs") {
            $this->savePrefs($post);
            exit(1);
        }
        
         // more omitted for sanity
    }

    public $tabs =array();
    public $sidebarDefault =  array();
    public $auxInfo = array();
    public $metricDefault = array();
    public $sidebar = array();

    public $client = array(
        dataSets => array(),
        unique => array(),
        data => array(),
        totals => array(),
        gauge => array(),
    );

    public $design = array(
        calc =>array(),
        comp =>array(),
        range=>array(),
        total =>array()
    );

    public $ignoreColumns = array();

    public function jsonReturn ($data){
        unset($data['clause']);
        $data json_encode($data);
        echo $data;
        exit(1);
    }

    public function run (){
        $list =func_get_args();
        $func $list[0];
        if(!method_exists($this,$func)) return;
        $vars array_slice($list,1);
        return call_user_func_array(array($this,$func),$vars);
    }

    public function getPref (){ global $userid$commondb;  // more omitted for sanity }
    public function savePrefs ($response){}
    public function getRecord($post){ global $database$main;  // more omitted for sanity }

    public function isBuilt($post){
        global $database,$userid;
         // more omitted for sanity
        exit(1);
    }

    public function allFieldExists($list$structure){}
    public function buildNewTable($post){ global $database,$main// more omitted for sanity }
    public function getReportCode($r false){}
    public function checkIfexists($post){ global $database,$main;  // more omitted for sanity }
    public function formulateTabs ($response){}
    public function reportPicker (){ global $main$userid$database;  // more omitted for sanity }

    public function buildModel ($post){
         // more omitted for sanity
        exit(1);
    }

    public function genCustCodes (){ global $userid;  // more omitted for sanity }
    public function add_unique_item($lib$key){}

    public function buildMyStructure ($post){
        global $main;
        $query = new \QueryBuilder($this);
         // more omitted for sanity
    }

    function snapshot ($post){
        global $userid$database;
        $clause $this->makeClause($post);
        $post['command'] = str_replace("'","''",$post['command']);
        list($now) = getsqlfields($database,"select now()");
        $now str_replace(" EST","",$now);
        $sql "insert into dashboard_snapshots values ('{$post['naming']}','{$this->getReportCode($post)}','$userid','$clause', '{$post['command']}','$now')";
        pg_query($database,$sql);
        $response = array(
          sql => $sql,
          dcr =>$now,

        );
        echo json_encode($response);
    }

    function saveSnaps ($post){}
    function createFavorite ($post) {}
    function detail ($post){}

    public function primary($post) {
        // ... more stuff ...
        exit(1);
    }

    public function getMyDateRange ($sidebar){}
    public function generateUnique ($response){}
    public function generateUnique3 ($columns){}

    public function generateUnique4($response){
        global $database;
        $query $this->bufferTable();
        $response['query']=$query;
        ini_set("memory_limit","1000M");
        ini_set("max_execution_time","1200");
        ini_set("max_input_time","200");
        pg_query($database,'SET datestyle TO "ISO, YMD"');
        $data $this->runSQL($query);
        if(!$this->structureKey) return;

        // ... more stuff ...
    }

    public function buildSideBar (){}

    public function startDashboard($post){
        // more omitted for sanity
        echo json_encode($response);
        exit(1);
    }

    public function makeClause ($post){}

    public function getSnapShots ($post){
        global $database,$main;
        // ... more stuff ...
    }

    public function getFavorites ($post){
        global $commondb,$main;
        // ... more stuff ...
    }

    public function userAccess(){}
    public function add_unique_listItems($listItem,$key){}
    public function dataCalc ($dataItem,$group){}
    public function newDataItem (){}
    public function rangeList ($dataItem){}
    public function pullDataSet(&$post){}

    public function createDynamicReport ($post){
        // ... more stuff ...
        exit(1);
    }

    public function removeFile($post){
        // ... more stuff ...
        echo json_encode($response);
        exit(1);
    }

    public function saveFile($post){
        // ... more stuff ...
        echo json_encode($post);
        exit(1);
    }

    public function createList ($post){
        // ... more stuff ...
        echo json_encode($this->pullDataSet($post));
        exit(1);
    }

    public function kendoFormat($columnName){}

    public function createBaseData ($post){
        // ... more stuff ...
        $this->jsonReturn($record);
        exit(1);

    }

    public function setAsDefault($post){}
    public function accessDenied ($post){}
    public function getSourceFiles($post){}
    protected function bufferTable(){}
}

Dude who wrote this garbage gave me a 'demo' on this yesterday. It also featured another 1000+ line php class, then a couple ~500 line javascripts. Upon him opening this file:

Me: Whoa
Him: Yeah, it's a bit long. I'm not really sure how long classes are supposed to be. :downs:
Me: :yikes:

xzzy
Mar 5, 2009

Should have told him the maximum is 100 lines.

Probably wouldn't hurt since apparently they have no intention of learning any of the theory.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
All the grades are in on this class. Go hog wild:
http://pages.cs.wisc.edu/~cs537-2/
http://en.wikipedia.org/wiki/Perry_Kivolowitz

This last project in particular suffers from being a quickly banged-out wall of text with too much emphasis on being "funny". There are at least 5 instructions in here that turned out to be factually incorrect:
http://pages.cs.wisc.edu/~cs537-2/projects/p5.html

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

LeftistMuslimObama posted:

All the grades are in on this class. Go hog wild:
http://pages.cs.wisc.edu/~cs537-2/
http://en.wikipedia.org/wiki/Perry_Kivolowitz

This last project in particular suffers from being a quickly banged-out wall of text with too much emphasis on being "funny". There are at least 5 instructions in here that turned out to be factually incorrect:
http://pages.cs.wisc.edu/~cs537-2/projects/p5.html

Doesn't Wikipedia have a policy about people not making pages about themselves unless they're actually a notable public figure? I figure you might be able to get him deleted in revenge.

Polio Vax Scene
Apr 5, 2009



537 as an introductory class in a US university?

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
^^ Yeah, this school is weird and all of the CS courses after Data Structures are 400-level at a minimum. None of my undergrad credits transferred because the school I went to used the usual 1xx,2xx,3xx convention.

Volmarias posted:

Doesn't Wikipedia have a policy about people not making pages about themselves unless they're actually a notable public figure? I figure you might be able to get him deleted in revenge.

Eh, I think it's better to leave it there as a monument to how self-absorbed he is.

edit: One last fuckup I forgot to mention. By school policy, final grades are due 6 days after the final exam. The final project wasn't graded until 10 days after the exam. They just graded the exam today, 12 days after it was given. I ended up filing a complaint with the registrar, because I can't get reimbursed by my work until I have a final grade and in the mean time the tuition is racking up interest on a credit card.

The MUMPSorceress fucked around with this message at 17:30 on May 19, 2015

Deus Rex
Mar 5, 2005

Scaevolus posted:

code:
var commandProbability = 0.03; //This is actually ~2% because Math.random doesn't include 1.0
var commandThreshold = Math.random() + commandProbability;

if (commandThreshold > 1) {

:3:

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
In slightly better news about this class, my perfect sweep on the projects boosted my low-B exam performances such that I ended up setting the curve and have the "highest" A in the class according to the instructor. I am finding that I'm way better at the hands-to-keyboard stuff than the theory stuff. Clearly I will not be pursuing a master's degree ever.

tyler274
Jul 1, 2014
Friend of mine works at a certain large firm and had this to say on the Enlightenment Foundation Libraries.

http://what.thedailywtf.com/t/enlightened/8795

Look in the comments for one of the developers of the libraries having a meltdown and some good points and counterpoints.

notably this is an error you could get at the time he posted that:

let's not forget the library printing "“You bitch!” to the console on a certain error (The developer removed this during his aforementioned meltdown.)

tyler274 fucked around with this message at 19:01 on May 19, 2015

Munkeymon
Aug 14, 2003

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



tyler274 posted:

Friend of mine works at a certain large firm and had this to say on the Enlightenment Foundation Libraries.

http://what.thedailywtf.com/t/enlightened/8795

Look in the comments for one of the developers of the libraries having a meltdown and some good points and counterpoints.

notably this is an error you could get at the time he posted that:

let's not forget the library printing "“You bitch!” to the console on a certain error (The developer removed this during his aforementioned meltdown.)

You forgot

quote:

And did I mention EFL is the basis of all applications on Tizen?

:china: I hope this thing dies in its crib before it can spread to the rest of the world

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Munkeymon posted:

You forgot


:china: I hope this thing dies in its crib before it can spread to the rest of the world

Isn't TIzen just Samsung's card they keep in their back pocket in case they ever need to extort Google on an Android design decision by threatening to take their ball and go home? I doubt it'll ever see the light of day. Android's too entrenched now and I don't think they'll be able to compete because people see smartphones as a binary choice between an "Android" and an iPhone.

Thermopyle
Jul 1, 2003

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

LeftistMuslimObama posted:

Isn't TIzen just Samsung's card they keep in their back pocket in case they ever need to extort Google on an Android design decision by threatening to take their ball and go home? I doubt it'll ever see the light of day. Android's too entrenched now and I don't think they'll be able to compete because people see smartphones as a binary choice between an "Android" and an iPhone.

People see smartphones as a choice between a Samsung and an iPhone. Most people barely know what the word Android means in this context.

But regardless, this Tizen thing doesn't work as a threat because it doesn't have much in the way of apps.

Munkeymon
Aug 14, 2003

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



LeftistMuslimObama posted:

Isn't TIzen just Samsung's card they keep in their back pocket in case they ever need to extort Google on an Android design decision by threatening to take their ball and go home? I doubt it'll ever see the light of day. Android's too entrenched now and I don't think they'll be able to compete because people see smartphones as a binary choice between an "Android" and an iPhone.

People in the US do, but in other markets even Windows and loving BBY still have a share greater than statistical uncertainty. Hell, sometimes I get mad enough at my phone that I feel like defecting to Windows.

Oh, they've subjected Indians to this thing http://arstechnica.com/gadgets/2015/02/samsung-z1-review-the-first-tizen-smartphone-still-feels-like-plan-b/4/ great. It's like they had a meeting that went like

"Hey, you know all those Android S-Apps that we bundle that nobody uses except by accident?"
<heads nod, approving murmurs can he heard>
"We're going to make a whole OS like that!"
<chorus of cheerful cheers>

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

LeftistMuslimObama posted:

Isn't TIzen just Samsung's card they keep in their back pocket in case they ever need to extort Google on an Android design decision by threatening to take their ball and go home? I doubt it'll ever see the light of day. Android's too entrenched now and I don't think they'll be able to compete because people see smartphones as a binary choice between an "Android" and an iPhone.

Tizen is on Samsung TVs in the wild.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Subjunctive posted:

Tizen is on Samsung TVs in the wild.

Also their Smartwatches. Although I would be surprised if anyone actually uses them right now though, considering they only work with Samsung phones.

JawnV6
Jul 4, 2004

So hot ...

Subjunctive posted:

Tizen is on Samsung TVs in the wild.

On purpose? Or did it escape from containment?

Vanadium
Jan 8, 2005

EFL don't seem fun to use but the shitposters in the comments come off looking worse than the dev trying to defend their design decisions.

Hammerite
Mar 9, 2007

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

Vanadium posted:

EFL don't seem fun to use but the shitposters in the comments come off looking worse than the dev trying to defend their design decisions.

It's worse than GBS over there.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
One of our internal tools is basically a wrapper around a keypass database to launch sessions in all our internal unix environments. I just discovered that it can't handle passwords containing spaces unless you surround your password with quotes. So, if my password is Pass Word, I have to enter "Pass Word" in the application to be able to connect to my environment. The developer has chosen not to put the code into any of the SVN repositories (a horror in itself), so I can't find the offending code, but I can only assume that he's not escaping the password before passing it to PuTTY as an argument, because the bug doesn't happen with another terminal emulator that is launched via RPC rather than invoked via the system.

Plorkyeran
Mar 22, 2007

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

Vanadium posted:

EFL don't seem fun to use but the shitposters in the comments come off looking worse than the dev trying to defend their design decisions.
The shitposters can at least write coherent sentences.

shodanjr_gr
Nov 20, 2007

tyler274 posted:

Friend of mine works at a certain large firm and had this to say on the Enlightenment Foundation Libraries.

http://what.thedailywtf.com/t/enlightened/8795

Look in the comments for one of the developers of the libraries having a meltdown and some good points and counterpoints.

notably this is an error you could get at the time he posted that:

let's not forget the library printing "“You bitch!” to the console on a certain error (The developer removed this during his aforementioned meltdown.)

So I don't get how a person who has the technical knowhow to implement the following:

quote:

Don’t use pointers as pointers. Split the bits in them into 3 (or 4) groups, which would be cast to a numerical indexes into 3- (or 4-) dimensional hash map, which in turn results in a real pointer to function + object, and call it, if such exist.

yet lacks the experience or common sense to realize why this (or anything else in the OP link) is a terrible idea.

fritz
Jul 26, 2003

tyler274 posted:

Friend of mine works at a certain large firm and had this to say on the Enlightenment Foundation Libraries.

Oh geez it's that enlightenment that was the window manager from back in the day.

quote:


Version 0.17, also referred to as E17, was in development for 12 years starting in December 2000[5] until 21 December 2012 when it was officially presented to the world as a stable release.[6] During the development period it was also referred to as DR17 (Development Release 17).

It is a complete rewrite on DR16 and was designed to be a full-fledged desktop shell, based on the new Enlightenment Foundation Libraries (EFL).

E16 itself is still in active development that runs independently of E17, reaching the 1.0 milestone in 2009 (1.0.14 as of 2014).

xzzy
Mar 5, 2009

X window managers are a coding horror in a category of their own, there's been more from scratch "minimalist" implementations that slowly turn into bloated monsters than any other software type.

fritz
Jul 26, 2003

xzzy posted:

X window managers are a coding horror in a category of their own, there's been more from scratch "minimalist" implementations that slowly turn into bloated monsters than any other software type.

Two or three lives ago I put a bunch of effort into getting my ctwm config just the way I wanted it for maximum productivity, then I spent years in a corporate environment and came out figuring that as long as a WM wasn't horrible it was good enough.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

shodanjr_gr posted:

So I don't get how a person who has the technical knowhow to implement the following:


yet lacks the experience or common sense to realize why this (or anything else in the OP link) is a terrible idea.

I finally clicked the link and read that whole article. Holy hell...

tyler274
Jul 1, 2014

Subjunctive posted:

Tizen is on Samsung TVs in the wild.

Funny story, the youtube app on Tizen TV has full root access.

Lots of security holes like this across the entire thing due to stupid decisions by management from what I understand.

KaneTW
Dec 2, 2011

quote:

http://what.thedailywtf.com is now being blocked on the corporate firewall at Samsung.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Lol. My company encourages us to read the blogs that poo poo talk us because you can farm their criticism for ideas for improvement when people aren't outright trolling.

edit: That is to say, we're actually expected to be reading blogs on the clock, not just in our free time.

Harik
Sep 9, 2001

From the hard streets of Moscow
First dog to touch the stars


Plaster Town Cop
Well, that's certainly one way to make sure your people don't find out about how bad things are, I guess they assume everyone will honor their firewall even at home, too.


I ran across this when looking up the named arguments pattern in C++, this is the C++11 way:
C++ code:
class kwarg {
public:
    kwarg() = default;
    kwarg(const char* name)
        : name(name) { }

    struct kwarg_proxy_base { virtual ~kwarg_proxy_base() {}; };

    template <typename T>
    struct kwarg_proxy : kwarg_proxy_base {
        kwarg_proxy() = default;
        kwarg_proxy(const T& t)
            : t(t) { }
        typedef T type;
        const T& t;
    };

    kwarg& operator=(kwarg& rhs)
    {
        value = rhs.value;
        return *this;
    }

    template <class T>
    kwarg& operator=(const T& rhs)
    {
        value = std::shared_ptr<kwarg_proxy_base>(new kwarg_proxy<T>(rhs));
        return *this;
    }

    kwarg& operator=(const char* rhs)
    {
        char_value = std::string(rhs);
        value = std::shared_ptr<kwarg_proxy_base>(
                new kwarg_proxy<std::string>(char_value));
        return *this;
    }

    template<typename T>
    operator const T&() const {
        if (!value) return T();
        return dynamic_cast<const kwarg_proxy<T> &>(*value).t;
    }

    template <typename T>
    operator T*() const {
        if (!value) return nullptr;
        return &dynamic_cast<const kwarg_proxy<T> &>(*value).t;
    }

    template <typename T>
    operator T() const {
        if (!value) return T();
        return dynamic_cast<const kwarg_proxy<T> &>(*value).t;
    }

    const std::string name;
    std::string char_value;
    std::shared_ptr<kwarg_proxy_base> value;
};

kwarg operator "" kw (const char* literal, size_t n)
{
    return kwarg(literal);
}

class kwargs : public std::map<std::string, kwarg> {
public:
    template <typename T>
    const T& get(const std::string& key, const T& default_parameter = T()) const
    {
        auto it = this->find(key);
        if (it == this->end()) 
            return default_parameter;
        if (it->second.value) 
            return it->second;
        return default_parameter;
    }

    template <typename T>
    T get(const std::string& key, T default_parameter = T())
    {
        auto it = this->find(key);
        if (it == this->end()) 
            return default_parameter;
        return it->second;
    }
};

void greet(const kwargs& kw = kwargs())
{
    std::string name = kw.get("user", std::string("somebody"));
    std::cout << "Hello, " << name << "!" << std::endl;
}

template <typename... Args>
void greet(kwargs kw, kwarg k, Args... args)
{
    kw[k.name] = k;
    greet(kw, args...);
}

template <typename... Args>
void greet(kwarg k, Args... args)
{
    kwargs kw;
    kw[k.name] = k;
    greet(kw, args...);
}

int main()
{
    greet("user"kw="Justin");
    greet();
}
I mean, it's a clever use of a new feature, but not what I was looking for:
code:
Label DefaultLabel=Label()
    .Name("test")
    .Size(14)
    .Style(STYLE_BOLD);
This is the standard C++ pattern, I was actually looking to see if you could extend it properly while using new:
code:
   butt=new Butt()->something()->else();
but operator new doesn't work that way, and while you could use parens it's clearer to just set the options on the next line.

In the end I decided against any of them, it either scans like someone forgot a trailing semicolon and throws you off, or leads to overly long lines that do too many different things.

Harik fucked around with this message at 05:45 on May 20, 2015

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
That is just a thing one person wrote that has never been used for a real project, not "the c++11 way".

Harik
Sep 9, 2001

From the hard streets of Moscow
First dog to touch the stars


Plaster Town Cop

Plorkyeran posted:

That is just a thing one person wrote that has never been used for a real project, not "the c++11 way".

I'm well aware. It's only c++11 in that they're abusing the new features 11 brought. Are there good examples of operator "", or is it just there to be a lurking horror?

QuantumNinja
Mar 8, 2013

Trust me.
I pretend to be a ninja.
code:
    public static boolean divisibleByFive (int n) {
        String s = Integer.toString(n);
        if (s.charAt(s.length() - 1) == '5' || s.charAt(s.length() - 1) == '0') 
            return true;
            
        return false;            
    }
Saw this in a production codebase last month.

Contra Duck
Nov 4, 2004

#1 DAD
"Division is a very costly operation so I optimised it"

Hammerite
Mar 9, 2007

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

QuantumNinja posted:

code:
    public static boolean divisibleByFive (int n) {
        String s = Integer.toString(n);
        if (s.charAt(s.length() - 1) == '5' || s.charAt(s.length() - 1) == '0') 
            return true;
            
        return false;            
    }
Saw this in a production codebase last month.

Suggest to them it's not general enough and they should do it like this instead

code:
    public static boolean divisibleBy (int n, int r) {
        String s = Integer.toString(n, r);
        if (s.charAt(s.length() - 1) == '0')
            return true;
            
        return false;            
    }

Adbot
ADBOT LOVES YOU

Carthag Tuek
Oct 15, 2005

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



QuantumNinja posted:

Saw this in a production codebase last month.

Just check if the last 3 bits are 101 or 000 :shepface:

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