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
McGlockenshire
Dec 16, 2005

GOLLOCKS!

Jabor posted:

Is the first thing that gets done to the result of that query a split on `~'?
Why yes, that's exactly it. And can you guess what happens next?

Adbot
ADBOT LOVES YOU

NotShadowStar
Sep 20, 2000
I'm getting this tickling feeling that the whole thing would be done better by BETWEEN time AND time_spent

tef
May 30, 2004

-> some l-system crap ->

McGlockenshire posted:

Why yes, that's exactly it. And can you guess what happens next?

a split on :

looks like someone only knows how to extract one value from a database call?

tef
May 30, 2004

-> some l-system crap ->

Tux Racer posted:

To my defense though, there is nothing in the API that says it formats it based on characters, not spacing.

there was nothing on the knife that said don't place in eye socket.


so, now can we get a special case for newlines, whitespace, ascii control codes, unicode space. if you want a language that does this sort of poo poo, use php.

(ie the coding horror is you)

Thermopyle
Jul 1, 2003

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

tef posted:

there was nothing on the knife that said don't place in eye socket.


so, now can we get a special case for newlines, whitespace, ascii control codes, unicode space. if you want a language that does this sort of poo poo, use php.

(ie the coding horror is you)

I like you.

tef
May 30, 2004

-> some l-system crap ->
I mean it should have known I was writing to a CSV, HTML, XML, JSON file and escaped the character appropriately, I mean how was I meant to know it worked on *characters*

*snort*

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Tef: hey dude, it's 2011.

tef
May 30, 2004

-> some l-system crap ->
is this a I am old thing?

i.e shut up old man, we don't have time to learn from your mistakes we're moving too quickly and have to make our own mistakes

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.
Yes, in 2011 every library should be expected to know about every file format, terminal, and other sinks, including the kitchen's. None of these things take time or testing; do it goddamn it!

RitualConfuser
Apr 22, 2008
Just to beat this dead horse some more...

From Joshua Bloch's "How to Design a Good API and Why it Matters" talk:

quote:

Most API designs are over-constrained
  • You won't be able to please everyone
  • Aim to displease everyone equally

tef
May 30, 2004

-> some l-system crap ->
the talk is awesome, and the slide deck is so verbose you can just read it instead:

http://aarontgrogg.com/wp-content/uploads/2009/09/How-to-Build-API-and-why-it-matters.pdf

Dren
Jan 5, 2001

Pillbug

tef posted:

there was nothing on the knife that said don't place in eye socket.


so, now can we get a special case for newlines, whitespace, ascii control codes, unicode space. if you want a language that does this sort of poo poo, use php.

(ie the coding horror is you)

Forget php, he could write a really good regex that would just do it. It'll be so easy!

RitualConfuser
Apr 22, 2008

tef posted:

the talk is awesome, and the slide deck is so verbose you can just read it instead:

http://aarontgrogg.com/wp-content/uploads/2009/09/How-to-Build-API-and-why-it-matters.pdf

I'll also give some anecdotal evidence to support the reasoning behind some of the ideas in this talk. Bloch's experience is miles beyond my mine but, sometimes it helps to have specific examples to illustrate why a best practice is actually a best a practice.

I worked on a project where we had inherited a bunch of code from a legacy system. The part of the team that was assigned to my area was working mainly on the central data access component of the legacy system. The original intent of that component was to provide data in a format that was a low level common abstraction that was useful for all users of the component (going back to the "pissing everyone off equally" mentality). That worked well for a while but, eventually, the data models from other parts of the system were moved into the central data access component.

This seemed great from the perspective of the groups who were moving their data models from their components into the central data access component; less code for them to maintain. The problem was that, of course, the knowledge of why these data models existed in the first place was lost. So, now, the maintainers of the central data component had to deal with a lot of issues and bugs with data models of which they had no knowledge about and, these issues distracted from their real focus of making data available in the "lowest common denominator" format.

A few years down the road, as the cycle continues, a new project came along that needed to use this central data access module, since not doing so would mean a huge increase in cost to the customer; management had already sold the customer on the fact that we already had a lot of existing functionality that we could leverage.

The main problem was that, the precedence had been set as far as this central data access component being responsible for providing data in whatever format anyone else wants the data in. Fighting this decision took a considerable amount of time and money. Eventually, the correct decision was made to move the external component specific data models back into the components that needed them but, it took a lot of time and money to get everyone to agree on that.

So, moral of the story is, again, an API will generally not fill your specific needs. However, there is often a reasonable explanation behind this; and, if the API is designed correctly, the API will provide building blocks that you can then use to create what you need.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

tef posted:

(ie the coding horror is you)
we obviously need a Coder Horror thread
for example:
https://groups.google.com/group/microsoft.public.win32.programmer.kernel/browse_thread/thread/6326c306e22e05bb/c0fee26e301bbcf2
wherein a programmer decides to use 32-bit Windows process IDs as 16-bit indexes to a flat array and refuses to listen to everybody saying "what, no"

quote:

Obviously I can't disclose the underlying motivation but suffice to say it has reduced a small CPU intensive bottleneck in an area that is otherwise impossible to address, we are seeing a 50% drop in CPU on an operation that is small but performed frequently in our case.

MrMoo
Sep 14, 2000

I like that, "Obviously".

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock
What the gently caress are they doing where looking up stuff by process ID is so time critical it accounts for a 50% speed increase?

Vinterstum
Jul 30, 2003

ymgve posted:

What the gently caress are they doing where looking up stuff by process ID is so time critical it accounts for a 50% speed increase?

50% speed increase of that operation, even. Whatever they're doing, they probably shouldn't be doing it.

I like how the guy is defending his decision by talking about his 40 years in the industry and all the stuff he's done...

Karanth
Dec 25, 2003
I need to finish Xenogears sometime, damn it.

Vinterstum posted:

50% speed increase of that operation, even. Whatever they're doing, they probably shouldn't be doing it.

I like how the guy is defending his decision by talking about his 40 years in the industry and all the stuff he's done...

I like how he's defending his decision against a member of the windows kernel team.

In a more perfect world the people who implement internals of widespread systems like this will occasionally change some undefined behavior just to teach people like this a lesson and have it serve as a public warning to others. :colbert:

pseudorandom name
May 6, 2007

Except that working around the stupidity of others is one of the reasons why Windows is such a huge success.

Karanth
Dec 25, 2003
I need to finish Xenogears sometime, damn it.

pseudorandom name posted:

Except that working around the stupidity of others is one of the reasons why Windows is such a huge success.

There's commitment to back compatibility and then there's the stuff Raymond Chen writes about.

That ridiculous thread posted:

Whilst I don't agree with all your points, I must say that this
comment is spot on. If Microsoft is concerned about people "making
design decisions based on internal/undocumented implementations and
not the public contract" they need to put much more effort into
correcting the errors and omissions in the Win32 API documentation.

Documentation being outright wrong is one thing, but undefined behavior is left undefined for a reason. :bang: It's undefined because it does not matter as long as you're doing things right, it cannot be relied upon, and it may change for any reason. Declaring every internal detail in API docs breaks encapsulation just like exposing implementation details in the API itself does.

evensevenone
May 12, 2001
Glass is a solid.

Karanth posted:

Documentation being outright wrong is one thing, but undefined behavior is left undefined for a reason. :bang: It's undefined because it does not matter as long as you're doing things right, it cannot be relied upon, and it may change for any reason. Declaring every internal detail in API docs breaks encapsulation just like exposing implementation details in the API itself does.

I don't have precise examples, but one of the things that came up in the MS antitrust cases was that the APIs had many many undocumented but public interfaces, and that Microsoft would use them in their own products. So their products (eg Office or whatever) could do things that could not be done using only the API as described in the documentation. A lot of people reverse engineered the API features, but Microsoft would change them in a way that would break other products but not their own. When the NT code was leaked, they found tons of workarounds to prevent Office etc from breaking due to it using an undocumented feature that had been changed.

In the intervening years I think Microsoft has gotten a lot better in that respect, probably as a result of open source and the realization that they need to support Windows developers as much as possible rather than seeing them as competitors and throwing them under the bus whenever possible. And MSDN has gotten really really good.

Karanth
Dec 25, 2003
I need to finish Xenogears sometime, damn it.

evensevenone posted:

I don't have precise examples, but one of the things that came up in the MS antitrust cases was that the APIs had many many undocumented but public interfaces, and that Microsoft would use them in their own products. So their products (eg Office or whatever) could do things that could not be done using only the API as described in the documentation. A lot of people reverse engineered the API features, but Microsoft would change them in a way that would break other products but not their own. When the NT code was leaked, they found tons of workarounds to prevent Office etc from breaking due to it using an undocumented feature that had been changed.

In the intervening years I think Microsoft has gotten a lot better in that respect, probably as a result of open source and the realization that they need to support Windows developers as much as possible rather than seeing them as competitors and throwing them under the bus whenever possible. And MSDN has gotten really really good.

I understand what you're saying about Microsoft specifically, but I'm fully in favor of punishing anyone who relies on undefined behavior equally. Apps made by the same company don't get a pass, if anything that's even more reason why they should know better. :colbert:

Randel Candygram
Jun 21, 2008

College Slice
Just going to throw this out here:

code:
static inline size_t virt_to_offset(uint64_t virt, unsigned depth) {
    // There's a good reason for this, but I just vomited half a pound of raw
    // meat and don't really feel like writing good comments right now. So
    // you can just deal with it.
    return (virt >> (39 - 9*depth))&0x1FF;
}

shrughes
Oct 11, 2008

(call/cc call/cc)

Randel Candygram posted:

Just going to throw this out here:

code:
static inline size_t virt_to_offset(uint64_t virt, unsigned depth) {
    // There's a good reason for this, but I just vomited half a pound of raw
    // meat and don't really feel like writing good comments right now. So
    // you can just deal with it.
    return (virt >> (39 - 9*depth))&0x1FF;
}

So they have a tree of 4096-byte pages, a straightforward fixed-depth sparse vector with each node taking exactly one page. What's the horror?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

shrughes posted:

So they have a tree of 4096-byte pages, a straightforward fixed-depth sparse vector with each node taking exactly one page. What's the horror?

I think some would find the vomiting of raw meat kind of horrible. Also making a comment that says "I'm not explaining this" and then never going back and fixing it.

TasteMyHouse
Dec 21, 2006

Aleksei Vasiliev posted:

we obviously need a Coder Horror thread
for example:
https://groups.google.com/group/microsoft.public.win32.programmer.kernel/browse_thread/thread/6326c306e22e05bb/c0fee26e301bbcf2
wherein a programmer decides to use 32-bit Windows process IDs as 16-bit indexes to a flat array and refuses to listen to everybody saying "what, no"

quote:

This is called thinking out of the box incidentally, for those of an overly
conservative mindset.
holy poo poo kill this man

Randel Candygram
Jun 21, 2008

College Slice

shrughes posted:

So they have a tree of 4096-byte pages, a straightforward fixed-depth sparse vector with each node taking exactly one page. What's the horror?

Do you often ship code detailing your meat-vomiting habits?

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

quote:

I really don't think it is possible to develop non-trivial working software
systems when one relies soley on written documentation, it just doesn't
happen

However, it is possible to develop non-trivial working software systems that don't make assumptions that are trivially falsifiable.

Incoherence
May 22, 2004

POYO AND TEAR

Randel Candygram posted:

Do you often ship code detailing your meat-vomiting habits?
http://www.vidarholen.net/contents/wordcount/

Dren
Jan 5, 2001

Pillbug

tef posted:

the talk is awesome, and the slide deck is so verbose you can just read it instead:

http://aarontgrogg.com/wp-content/uploads/2009/09/How-to-Build-API-and-why-it-matters.pdf

As someone who has spent a lot of time sitting, thinking of a good name for something when I could've been coding instead I find this bit very encouraging.

quote:

Functionality should be easy to explain
_ If it's hard to name, that's generally a bad sign
_ Good names drive development

tef
May 30, 2004

-> some l-system crap ->
a framework I wrote for a previous company had some things for getters/setters for a http request (i.e post vars, charset - to handle encoding and bits).

I agonized over the name and ended up with one name in particular being terrible -- but moved on as I didn't have enough time.

Turns out it is one of the major complaints about it :3:

NotShadowStar
Sep 20, 2000
Here's a fun thing. Been working with Flash on a side project. Internally Flash uses a dialect of ECMAScript, but instead of taking the opportunity on fixing up ECMAScript, Adobe instead turns it into Yet Another Java Style Language (YAJSL). This is probably because old ActionScript was slow, and Adobe's terrible middle eastern factory line programmers can't figure out how to optimize a dynamic langage.

So that's bad enough, but the real horror starts when you run into the problem that the Flash VM is different in Internet Explorer than the Everything Else VM. For instance, this works fine in any other Flash VM

code:
package {
class Fart {
  import flash.media.*;
  private var _channel:SoundChannel;
  private var _sound:Sound = new Sound("banaphone.mp3");

  public function Fart() {
    _channel = _sound.play(_position);
  }
}
}
There's no stated need on creating a variable reference when you first declare it according to AS3 that I can see. But this fails on _sound.play() in the IE VM with a Null Reference Error. Yet it works on every other Flash VM.

Fixing it requires this:
code:
private var _channel:SoundChannel = new SoundChannel();
Second, there's another huge crawling horror that nobody will own up to. Either Adobe or Microsoft has undocumented reserved keywords that silently, mysteriously fail when you access them. IE has some lurking keywords that you can't use (try using the word 'class' in IE's Javascript) so I'm guessing that's the culprit. At any rate, when connecting Flash to the browser you pass in a string and a reference to the internal Flash function you want called:

code:
ExternalInterface.addCallback('play', AwesomeSauce.play);
This works in everything... except Internet Explorer again. Doing flashElement.play() in Internet Explorer throws an 'Object does not support this property or method' error. Fun times! Naming the exposed callback to anything but play, like dickbutt, works fine. Nobody has ever figured out a list of these reserved words or who's the culprit, so the standard practice for making exposed functions in Flash is to prefix them with _.

Microsoft and Adobe: Together it's like Godzilla and Mechagodzilla ravaging a city of weary developers who just want to Get poo poo Done, and would be if these loving lizards get off the lawn.

RitualConfuser
Apr 22, 2008

Dren posted:

As someone who has spent a lot of time sitting, thinking of a good name for something when I could've been coding instead I find this bit very encouraging.
If you ever get stuck, you can always just use the description as the name.
code:
    /**
        The list of ObjectIDs of objects which are surelyReachable and already were tried to
        be processed but where locking the objects failed. The processing the contents of this
        list should be retried some times later.

        To minimize overhead, access is only allowed during synchronization to 
        {@link #surelyReachableObjectsWhichHaveToBeMarkedAsSuch}
    */
    protected   LinkedList      surelyReachableObjectsWhichShouldHaveBeenProcessedButWereLockContented;

Thermopyle
Jul 1, 2003

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

Dren posted:

As someone who has spent a lot of time sitting, thinking of a good name for something when I could've been coding instead I find this bit very encouraging.

Doesn't that mean you've wrote a lot of bad code? I would find that discouraging.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Thermopyle posted:

Doesn't that mean you've wrote a lot of bad code? I would find that discouraging.

Like you only poo poo out gold nuggets?

Thermopyle
Jul 1, 2003

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

MEAT TREAT posted:

Like you only poo poo out gold nuggets?

No. I wasn't being disparaging anyone.

I was saying that from what he said, I didn't get how it would be encouraging.

Person 1: "I spend lots of time trying to come up with names"

Person 2: "Spending lots of time on naming is a bad sign."

Person 1: "I find that encouraging!"

Me: "What?"

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Thermopyle posted:

No. I wasn't being disparaging anyone.

I was saying that from what he said, I didn't get how it would be encouraging.

Person 1: "I spend lots of time trying to come up with names"

Person 2: "Spending lots of time on naming is a bad sign."

Person 1: "I find that encouraging!"

Me: "What?"

Dren's belief that naming is important was independently echoed, and Dren is encouraged by this.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
I regularly find naming to be the hardest part of development. However, I don't like the contention that being unable to name something means you don't have a good grasp on what the component's function is. While that certainly can be true I often struggle with naming something that I have a very clear idea on its role, I just can't think of a snappy way to sum that functionality up.

Maybe I just have a bad vocabulary but in my experience most devs share this problem.

tef
May 30, 2004

-> some l-system crap ->
naming things is one of the two hardest problems in computer science. the other two are cache invalidation and off by one errors.

Adbot
ADBOT LOVES YOU

evensevenone
May 12, 2001
Glass is a solid.
This is like a daily occurrence for me (i do lots of embedded state machines)
code:
typedef enum {entry, step1, step2, step3, finish} state_t;
Oh well.

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