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
Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
You're not allowed to redefine keywords at all if you use the standard library. I don't think the standard bothers to specify what happens if you don't use the standard library, which makes it implicitly UB.

Adbot
ADBOT LOVES YOU

shrughes
Oct 11, 2008

(call/cc call/cc)
You certainly could make some types become standard-layout types when they weren't before.

ToxicFrog
Apr 26, 2008


code:
eval(unsafeCustomerInput)
Actual production code, although thankfully not at my company. Yes, that is the real variable name.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I don't believe you.

Hughlander
May 11, 2005

shrughes posted:

Recently, I saw this...

code:

#define private public
#include "header_file.hpp"
#undef private

so that some unit test code could see private member functions.

I've seen that along with #define const in a PCH before.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Of course, the actual horror there is unit testing private methods. :v:

Coffee Mugshot
Jun 26, 2010

by Lowtax

Ithaqua posted:

Of course, the actual horror there is unit testing private methods. :v:

Unless you're teaching a programming class, and want some automated testing. I don't understand the need for the extra #undef private, am I missing something?

shrughes
Oct 11, 2008

(call/cc call/cc)

Voted Worst Mom posted:

Unless you're teaching a programming class, and want some automated testing. I don't understand the need for the extra #undef private, am I missing something?

It's to keep the scope of the change as limited as possible (out of other headers).

But it doesn't matter because it's still wrong, because it could very well cause binary incompatibility between different .cc files.

Zombywuf
Mar 29, 2008

The correct way is:
C++ code:
#ifndef _TESTING
    private:
#endif
:colbert:


The actual correct way is breaking your units down more so the private parts* are objects with public methods you can test.

* No sniggering at the back

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
If refactoring your code to not be terrible is too much work, friend classes are a far less bad way to expose your privates to the tests than preprocessor trickery.

FlapYoJacks
Feb 12, 2009
Ran across this in the kernel today (Freescale):

code:

/* STUFF */
cam->enc_counter = 0;
		INIT_LIST_HEAD(&cam->ready_q);
		INIT_LIST_HEAD(&cam->working_q);
		INIT_LIST_HEAD(&cam->done_q);

		vidioc_int_g_ifparm(cam->sensor, &ifparm);

		csi_param.sens_clksrc = 0;

		csi_param.clk_mode = 0;
		csi_param.data_pol = 0;
		csi_param.ext_vsync = 0;

		csi_param.pack_tight = 0;
		csi_param.force_eof = 0;
		csi_param.data_en_pol = 0;

		csi_param.mclk = ifparm.u.bt656.clock_curr;
/* STUFF */

See vidioc_int_g_ifparm? Yeah, there's no null checking at all there. Way to go freescale! If the device fails to enumerate on bootup, it tries to initiate a NULL. :bravo:

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
I was looking at the Oregon healthcare exchange website, specifically the way you sign up. It's IE-only, you only have one hour to complete the application, and you can't save. Also, "the Adobe Acrobat PDF plug-in is required to submit this application."

https://apps.state.or.us/mbs/landing.jspx

I'm sure at least some of the insanity comes from the way the state wanted to handle the applications coming in, but god drat. Designed and developed in just the past couple years >:[

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
IE only is probably just begging for some sort of accessibility lawsuit somewhere down the line. It is also kind of shocking given that msie is no longer the clear leader in market share.

Molten Llama
Sep 20, 2006
It's probably less shocking if you're aware it's another fine Oracle product.

kitten smoothie
Dec 29, 2001

I am stunned to see a "submittable" PDF document in TYOOL 2013. I've seen plenty of "fill-and-print" forms, but I haven't encountered the fully submittable kind since filling out college applications back in the '90s.

redleader
Aug 18, 2005

Engage according to operational parameters
Empty catch blocks are a bad practice, right?

C# code:
try
{
       // whatever
}
catch (Exception ex)
{
       string a = ex.ToString();
}
This is repeated three or four times in one file. The catch is, of course, reproduced in its entirety.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
I made a thing. iOS developers will probably empathize. An excerpt:

Objective-C code:
- (void)processCoolQueue
{
    if (isAnimating) {
        return;
    }

    if (self.coolInsertQueue.count == 0) {
        [self processCoolUpdateQueue];
        return;
    }

    MOCall *entry = [self.resultsController objectAtIndexPath:self.coolInsertQueue[0]];

    if (!entry) {
        [self uncoolReloadEventList];
        return;
    }

    isAnimating = YES;

    const CGFloat rowHeight = [CallHistoryCell rowHeightForMessage:[[PGSMMessaging sharedInstance] textOfMessage:entry]];
    
    CGSize contentSize = self.eventList.contentSize;
    CGFloat contentHeight = contentSize.height + rowHeight;
    CGFloat viewHeight = self.eventList.frame.size.height;
    CGFloat scrollY = viewHeight > contentHeight ? 0 : contentHeight - viewHeight;

    coolContentOffset = CGPointMake(0, scrollY);
    coolContentSize = contentSize;
    coolContentInset = UIEdgeInsetsMake(0, 0, rowHeight, 0);

    [UIView animateWithDuration:0.2
    animations:^{
        self.eventList.contentInset = coolContentInset;
        self.eventList.contentOffset = coolContentOffset;
    }
    completion:^(BOOL finished) {
        coolContentInset = UIEdgeInsetsZero;
        coolContentSize = CGSizeMake(contentSize.width, contentHeight);

        coolCellIndex = [self.coolInsertQueue[0] copy];
        coolCell = [[self reuseOrCreateCell] retain];
        coolCell.fixedFrame = CGRectMake(NAN, coolContentSize.height - rowHeight, NAN, rowHeight);

        coolCells = [self.eventList.visibleCells copy];

        for (CallHistoryCell *cell in coolCells) {
            cell.fixedFrame = cell.frame;
        }
        
        [CATransaction begin];
        
        [CATransaction setCompletionBlock:^{
            [self.coolInsertQueue removeObjectAtIndex:0];
            
            [coolCell resetFixedFrame];

            for (CallHistoryCell *cell in coolCells) {
                [cell resetFixedFrame];
            }

            [coolCellIndex release], coolCellIndex = nil;
            [coolCell release], coolCell = nil;
            [coolCells release], coolCells = nil;

            self.eventList.contentInset = coolContentInset;
            self.eventList.contentOffset = coolContentOffset;
            self.eventList.contentSize = coolContentSize;
            
            if (pendingReload) {
                self.coolInsertQueue = nil;
                self.coolUpdateQueue = nil;
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self uncoolReloadEventList];
                    pendingReload = NO;
                    isAnimating = NO;
                });
            }
            else {
                [self processCoolUpdateQueue];
                isAnimating = NO;
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self processCoolQueue];
                });
            }
        }];
        
        [self.eventList beginUpdates];
        
        ++ coolNumberOfRows;
        [self.eventList insertRowsAtIndexPaths:@[self.coolInsertQueue[0]] withRowAnimation:UITableViewRowAnimationLeft];
        
        [self.eventList endUpdates];
        
        self.eventList.contentInset = coolContentInset;
        self.eventList.contentOffset = coolContentOffset;
        self.eventList.contentSize = coolContentSize;
        
        [CATransaction commit];
    }];
}
UITableView is a glitchy piece of gross poo poo

hackbunny fucked around with this message at 11:52 on Dec 12, 2013

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Why are you not using ARC?!?!

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
A hipstery love of the warm analog smoothness of manual memory management? :shrug: It sure beats COM, I would have killed for autorelease pools back then

Huge legacy codebase, plus I've only been an iOS developer since April :ssh:

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Xcode's automatic converter works quite well. I was able to convert a ~20 kloc codebase to ARC in well under a day with it (although it'd be harder if the code does anything that can't be represented by ARC, naturally).

Kallikrates
Jul 7, 2002
Pro Lurker
Used the auto convert on some pretty large projects, if it comes across some code where that tool fails, it will alert you. Even more better, you can just flag that file as being non ARC and have it live side by side ARC code.

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

redleader posted:

Empty catch blocks are a bad practice, right?

C# code:
try
{
       // whatever
}
catch (Exception ex)
{
       string a = ex.ToString();
}
This is repeated three or four times in one file. The catch is, of course, reproduced in its entirety.

Most likely yes. At a minimum you probably should be logging the Exception even if you are swallowing it. I would also catch a more specific Exception so when you get an OutOfMemoryException it's does crash your application instead of allowing the application to live a little longer. If the code in the TRY block is throwing exception to alert you of information then change the code (if you can) to not throw an Exception unless something exceptional occurs.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug

gariig posted:

I would also catch a more specific Exception so when you get an OutOfMemoryException it's does crash your application instead of allowing the application to live a little longer.

There is no such thing as OutOfMemoryException. OutOfMemoryError is not a subclass of Exception and isn't covered by that catch block.

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

Lysidas posted:

There is no such thing as OutOfMemoryException. OutOfMemoryError is not a subclass of Exception and isn't covered by that catch block.

You are speaking Java but redleader posted it as a C# code example. In .NET land OutOfMemoryException is derived from Exception so OutOfMemoryException would be caught and swallowed. It still stands that most of the time you should not be swallowing the Exception class but I've done it in smaller utility applications. For Production code you really shouldn't be doing that.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
Ah, that makes sense. I apparently missed the "C#" at the top of the code block and the capitalized ToString. That's a strange exception hierarchy, though.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Pokemon exception handling is never good.

Sereri
Sep 30, 2008

awwwrigami

Ithaqua posted:

Pokemon exception handling is never good.

For a while now I've been playing with the idea to make an app based around Pokemon exceptions. Give the user the tools to cause exceptions and track which ones they already caused. Maybe make it possible to trade them even, I don't know. Maybe on a rainy weekend...

Glimm
Jul 27, 2005

Time is only gonna pass you by

I'm not sure whether or not this is a horror or a beautiful masterpiece:

https://github.com/bradfitz/goimports/pull/26#issuecomment-30389623

quote:

I don't know if this will go in my favor or against, but I happen to have a lot of small Go packages that are kept in a folder starting with a number.

E.g., http://godoc.org/gist.github.com/5892738.git

You can see it's actually imported and used by my code elsewhere:
http://godoc.org/gist.github.com/5892738.git?importers

In the process of experimenting with the field of software development, I've wanted to automate as many mundane things as possible. One goal I had was to be able to effortlessly factor out duplicated code from 2+ places into a new Go package, so said code can be imported and reused. I wanted to make it as close to a "one button press" affair as possible. That meant creating a new Go package had to be automated.

Computers aren't good with coming up with descriptive and unique package names (and I prefer to write code first, come up with good names afterwards... I'm very slow at coming up with names and don't want it to be a bottleneck), but they are good at creating UUIDs.

It just so happens that there's an easy to use API for creating Gists, and they are full-fledged git repos that can be git cloned, and hence go getted and then imported.

Despite having unreadable package names, I'm able to find funcs scattered across these gists by searching for their content: the actual func names. Those serve as my unique and descriptive identifiers. I'm working on ways to visualize and navigate code such that you can easily find out what comes from each import, etc.

If I were to host these snippet packages elsewhere, I could give them better base names that don't require renaming, like "go12345.git" instead of "12345.git". But given that things work well as is, I'd much rather if goimports simply did not skip folders starting with a number. I don't imagine it's gaining a lot by doing that.

Dietrich
Sep 11, 2001

Ithaqua posted:

Pokemon exception handling is never good.

I have an error logging application that practices Pokemon handling. :colbert:

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Glimm posted:

I'm not sure whether or not this is a horror or a beautiful masterpiece:

https://github.com/bradfitz/goimports/pull/26#issuecomment-30389623
Fascinating, a new tier of bad programming laziness. "Coming up with good names is hard, so I'm just not going to do it."

..btt
Mar 26, 2008
I've heard that sentiment from a lot of coders but I really don't understand it. I don't think I've ever taken longer than about 10 seconds to come up with an appropriate name for a variable, function, object or project. Are these guys using some wappy, super-abstract programming techniques or something?

zeekner
Jul 14, 2007

..btt posted:

Are these guys using some wappy, super-abstract programming techniques or something?

Yea, autism.

Zombywuf
Mar 29, 2008

Lysidas posted:

That's a strange exception hierarchy, though.

SomeException is-a Exception. Yeah, really weird.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

hackbunny posted:

UITableView is a glitchy piece of gross poo poo

I changed the cell layout and now it crashes again in [self.eventList endUpdates] :cripes: I give up, I'll just use reloadData

e: annnd it's glitchy as gently caress. I'm this close to just using a second UITableView and swapping between the two

hackbunny fucked around with this message at 18:41 on Dec 12, 2013

Sockser
Jun 28, 2007

This world only remembers the results!




Trying to do some stuff with the Google Drive API.

First of all, the v2 of their API got moved to NuGet but doesn't have all the required prereqs and then it looks like there's conflicts so I can't even get that to work,
so I get like, a v0 release (seriously all of this is horribly documented, too)

So then, You'd think getting values from a spreadsheet would be like
connect to google
get the doc by name
doc.sheets[0].content[0][0]

and there you've got your first cell

But it's this ungodly mess here just to read cells:
code:
SpreadsheetsService myService = new SpreadsheetsService("exampleCo-exampleApp-1");
            myService.setUserCredentials("email@dot.com", "password");


            SpreadsheetQuery query = new SpreadsheetQuery();
            SpreadsheetFeed feed = myService.Query(query);

            Console.WriteLine("Your spreadsheets:");
            foreach (SpreadsheetEntry entry in feed.Entries.Where(x => x.Title.Text.Equals("spreadsheet")))
            {
                Console.WriteLine(entry.Title.Text);

                AtomLink link = entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);

                WorksheetQuery query2 = new WorksheetQuery(link.HRef.ToString());
                WorksheetFeed feed2 = myService.Query(query2);

                foreach (WorksheetEntry worksheet in feed2.Entries)
                {
                    Console.WriteLine("\t" + worksheet.Title.Text);

                    AtomLink link2 = worksheet.Links.FindService(GDataSpreadsheetsNameTable.CellRel, null);

                    CellQuery query3 = new CellQuery(link2.HRef.ToString());
                    CellFeed feed3 = myService.Query(query3);

                    foreach (CellEntry cell in feed3.Entries)
                    {
                        Console.WriteLine("{0}:{1} - {2}", cell.Cell.Column, cell.Cell.Row, cell.Cell.Value);
                    }
                }
and then if you want to update them it's even more confusing and it's like impossible to find examples of people using this poo poo and at that point I just decide to give up and not do this project


Why couldn't it just be loving simple


e: I guess it's not really a horror; I just wanted to complain

Sockser fucked around with this message at 18:49 on Dec 12, 2013

Thermopyle
Jul 1, 2003

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

..btt posted:

I've heard that sentiment from a lot of coders but I really don't understand it. I don't think I've ever taken longer than about 10 seconds to come up with an appropriate name for a variable, function, object or project. Are these guys using some wappy, super-abstract programming techniques or something?

I've expressed that sentiment and I also don't think I've ever taken longer than 10 seconds to come up with an appropriate name.

10 seconds is a long time.

Plorkyeran
Mar 22, 2007

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

Sockser posted:

Trying to do some stuff with the Google Drive API.
The gdrive SDKs are just a thin wrapper around the terrible REST API with no real attempt at making it usable.

It is rather telling that I couldn't find any Google things that actually use the public API.

JawnV6
Jul 4, 2004

So hot ...
Even a crap name shouldn't be a major issue with proper tooling. Oh no, i've mislabeled a variable. This will take multiple keystrokes to unwind.

Zhentar
Sep 28, 2003

Brilliant Master Genius
Naming/renaming local variables is easy, but interfaces & classes that are part of your public API can be both difficult to name clearly, and nearly impossible to change. It's particularly troublesome when you might have many implementations of something.

Adbot
ADBOT LOVES YOU

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Yep, so let's go with 1899342 :v:

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