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
TheresaJayne
Jul 1, 2011

astr0man posted:

If it's obvious what your code is doing it doesn't need comments. In this case if your function was named handle_butts() or something it wouldn't need any additional explanation.

shouldnt that be called fondle_butts();

Adbot
ADBOT LOVES YOU

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


Visual basic in Excel :getin:

code:

Public Function getnumber(ByVal mystr As String)

Dim mynum As Double
On Error GoTo handleerr

getnumber = 0
mynum = mystr * 1#
getnumber = mynum
Exit Function

handleerr:

End Function

Karate Bastard
Jul 31, 2007

Soiled Meat

ErIog posted:

This is why I name all of my functions like "handle_butts_returns_false_if_butthandle_invalid_true_if_butthandling_successful_takes_single_butthandler_or_array_of_butthandles(ButtHandle butthandle = false, Array butthandles = [])"

The comment isn't there to tell you what the function does necessarily. It's there to tell you why the function exists and appropriate usage details. Not all of that information can fit in a function name.

"Array of butthandles" is now my new favourite collective noun variant for "colleague".

SirViver
Oct 22, 2008
Good comments.

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE

Subjunctive posted:

People who use the word "kernel" outside of actual privileged-operating-system-code are usually trying to excuse cleverness that doesn't pay for itself, or otherwise indulge their illusions of Kernighan-ness. Beware.

Or they're CUDA developers.

quote:

2.1. Kernels

CUDA C extends C by allowing the programmer to define C functions, called kernels, that, when called, are executed N times in parallel by N different CUDA threads, as opposed to only once like regular C functions.
http://docs.nvidia.com/cuda/cuda-c-programming-guide/#kernels

NVIDIA couldn't stop themselves from using the word that means "privileged OS code" everywhere else to name "random program that runs on the GPU".

Paul MaudDib fucked around with this message at 16:17 on Oct 15, 2014

shodanjr_gr
Nov 20, 2007
It's more than likely based on the mathematical interpretation of the word kernel so it's not that much of a horror.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Paul MaudDib posted:

Or they're CUDA developers.

http://docs.nvidia.com/cuda/cuda-c-programming-guide/#kernels

NVIDIA couldn't stop themselves from using the word that means "privileged OS code" everywhere else to name "random program that runs on the GPU".

Well, in graphics the term "kernel" goes back a long way as the core operation repeated as part of a filter or convolution or whatever. They get a pass.

canis minor
May 4, 2011


In the beginning I saw nice things (though why would you repeat SPEC in each line). Then I've gotten to hilarious part of DELIBERATE SPEC VIOLATION. Then I've gotten to the part where developer started arguing on what happens, and what should be happening (probably due to no spec regarding given thing) and just vents his frustration.

vvv Nubbin!

canis minor fucked around with this message at 17:00 on Oct 15, 2014

fritz
Jul 26, 2003

Subjunctive posted:

Well, in graphics the term "kernel" goes back a long way as the core operation repeated as part of a filter or convolution or whatever. They get a pass.

Shaders. Filters. Mappers. Sanders.

SirViver
Oct 22, 2008
Nah, that's from the Roslyn source code, which has to maintain spec violations that were present in the original C# compiler as to not introduce breaking changes.

I like the coding-to-spec style with literal sections of the spec copied out, in combination with extensive documentation and reasoning as to why certain code parts have to violate it.

If you check other files you'll also see examples of comments intended for outside consumption.

raminasi
Jan 25, 2005

a last drink with no ice
There has just got to be a formal, universal solution to this question of communication between humans.

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

Hughlander posted:

The last time I was paid to write C the compiler wouldn't complain about, but would ignore any part of an identifier after 8 letters.

ratbert90 posted:

Wow, that compiler must have been horribly lovely.

In 1985 or so, all C compilers were that lovely.

Soricidus
Oct 21, 2010
freedom-hating statist shill

astr0man posted:

If it's obvious what your code is doing it doesn't need comments. In this case if your function was named handle_butts() or something it wouldn't need any additional explanation.
This very day, I was briefly stumped by a bug caused by a method called getValidPositions not, in fact, returning a collection of valid positions.

Fortunately there was an accurate and detailed method comment that explained what it actually did, so I didn't have to reverse-engineer it like I would have if its author had subscribed to the opinions of some posters in this thread of horrors.

TheBlackVegetable
Oct 29, 2006

Soricidus posted:

This very day, I was briefly stumped by a bug caused by a method called getValidPositions not, in fact, returning a collection of valid positions.

Fortunately there was an accurate and detailed method comment that explained what it actually did, so I didn't have to reverse-engineer it like I would have if its author had subscribed to the opinions of some posters in this thread of horrors.

Seems that method should just be called getPositions. Or, apparently, "getValidPositionsExceptSometimesNotReadTheCommentsToSeeWhyNot"

... but how do you know the comment is accurate if you don't check the code?

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Progressive JPEG posted:

I think of comments as justification for why a given piece of code needs to exist, and of commit messages as justification for why that code needs to be changed. Otherwise why does it need to exist?

This is pretty close to my approach. An example paraphrased from one of my projects:

code:
# The string.gsub! method won't work here because $THIRD_PARTY_LIBRARY expects strings to be immutable.
string = string.gsub(/foo/, 'bar')
Here it's definitely helpful to explain why the string wasn't modified in place via gsub! (which a lot of developers would expect to be The Right Thing). That's an implementation detail that can't be expressed practically in method or variable names.

itskage
Aug 26, 2003


These were shared with me today:

code:
    if (!is_array($foo)) {
      $tmp = array();
      $tmp[0] = $foo;
      $foo = array();
      $foo = $tmp;
    }
code:
$foo = 0;
$bar = 0;
if(isset($_REQUEST['foo'])) $foo = $_REQUEST['foo'];
if(isset($_REQUEST['bar'])) $bar = $_REQUEST['bar'];
 
if(strlen($foo) > 0 && strlen($bar) > 0) {

The 2nd one is gold.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Since that looks like PHP, I'm gonna hazard a guess that strlen checks the length of the string "0" and returns 1?

substitute
Aug 30, 2003

you for my mum

itskage posted:

These were shared with me today:

code:
    if (!is_array($foo)) {
      $tmp = array();
      $tmp[0] = $foo;
      $foo = array();
      $foo = $tmp;
    }
code:
$foo = 0;
$bar = 0;
if(isset($_REQUEST['foo'])) $foo = $_REQUEST['foo'];
if(isset($_REQUEST['bar'])) $bar = $_REQUEST['bar'];
 
if(strlen($foo) > 0 && strlen($bar) > 0) {

The 2nd one is gold.

Does this person have a (mostly) JS background?

Xanthalan
Jan 28, 2009
I think I found a coding horror in .NET while debugging a stack overflow with FluorineFx and Amf3 serialization. The overflow happens when it attempts to serialize the instance for the AMF return object.

Is there actually a reason for this? Why would you want a copy of the exception in a collection inside of the exception?

code:
namespace System.Configuration
{
  [Serializable]
  public class ConfigurationErrorsException : ConfigurationException
  {
    ...

    public ICollection Errors
    {
      get
      {
        if (this._errors != null)
          return (ICollection) this._errors;
        return (ICollection) new ConfigurationException[1]
        {
          (ConfigurationException) new ConfigurationErrorsException(this.BareMessage, this.InnerException, this._firstFilename, this._firstLine)
        };
      }
    }

    ...
  }
}

Xanthalan fucked around with this message at 04:52 on Oct 17, 2014

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Are there other paths that might collect multiple exceptions in this._errors?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
If there's multiple configuration errors, it's nice to be able to report all of them at once rather than just the first one. Of course, if it's anything like the .NET codebases I've worked on that did similar things, there's zero places that actually have more than one exception in Errors and none of the code which handles the exceptions would do anything useful with them even if there were.

Xanthalan
Jan 28, 2009

Plorkyeran posted:

If there's multiple configuration errors, it's nice to be able to report all of them at once rather than just the first one. Of course, if it's anything like the .NET codebases I've worked on that did similar things, there's zero places that actually have more than one exception in Errors and none of the code which handles the exceptions would do anything useful with them even if there were.

Which is what it appears to be doing in exactly 3 places in everything I have gac'ed. All of which look like they are outputting the exception messages and stack traces to something.

Subjunctive posted:

Are there other paths that might collect multiple exceptions in this._errors?

I guess it does have a purpose. It looks like the first ConfigurationErrorsException that gets thrown gets passed around a bit and then new ones are added to it as they happen.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Subjunctive posted:

People who use the word "kernel" outside of actual privileged-operating-system-code are usually trying to excuse cleverness that doesn't pay for itself, or otherwise indulge their illusions of Kernighan-ness. Beware.

Even within privileged OS code, it's used to paper over a lot of terrible shortcuts ignoring that humans will someday read this text.

or are referring to the analysis term, or popcorn

NFX
Jun 2, 2008

Fun Shoe
code:
void ConvertLFToSpace(char* buff)
{
    unsigned int i;
    for (i = 0; i < strlen(buff); i++) {
        if (buff[i] == '\r') //\r = 10
            buff[i] = 32;
    }

}

void RemoveCRFromStr(char* Value)
{
    int i = 0;
    while (Value[i] != 0) {
        if (Value[i] == '\n')
            Value[i] = 0;
        i++;
    }
}
According to blame, they were written by the same person, at the same time.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

NFX posted:

code:
void ConvertLFToSpace(char* buff)
{
    unsigned int i;
    for (i = 0; i < strlen(buff); i++) {
        if (buff[i] == '\r') //\r = 10
            buff[i] = 32;
    }

}

void RemoveCRFromStr(char* Value)
{
    int i = 0;
    while (Value[i] != 0) {
        if (Value[i] == '\n')
            Value[i] = 0;
        i++;
    }
}
According to blame, they were written by the same person, at the same time.

All other issues aside, that single comment is absolutely amazing in how much it misses the point.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Why would you need comments just look at the descriptive function names, it is self-documenting!

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

pokeyman posted:

Why would you need comments just look at the descriptive function names, it is self-documenting!

Well, based on that code, self-documenting code and comments are both useless, so I guess we should use neither :v:

ctz
Feb 6, 2003

Paul MaudDib posted:

NVIDIA couldn't stop themselves from using the word that means "privileged OS code" everywhere else to name "random program that runs on the GPU".

Coding horrors: posts that make you laugh (or cry)

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

Paul MaudDib posted:

Or they're CUDA developers.

http://docs.nvidia.com/cuda/cuda-c-programming-guide/#kernels

NVIDIA couldn't stop themselves from using the word that means "privileged OS code" everywhere else to name "random program that runs on the GPU".

Is this post serious?

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

Oh no, the cancer has spread to signal processing textbooks! :ohdear:

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Blotto Skorzany posted:

Oh no, the cancer has spread to signal processing textbooks! :ohdear:



This entry is correct and accurate.

Unless you're trolling, in which case I'll use the kernel method of eating popcorn.

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 hope you've got butter and salt.

JawnV6
Jul 4, 2004

So hot ...
When code is "on the cob," formerly ring0,

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
To be fair, there is a ton of overloading of terms across computing, and if you've never taken a college algorithms class or read some graphics literature then you could easily have avoided other definitions of "kernel".

JawnV6 posted:

When code is "on the cob," formerly ring0,

:laffo:

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

JawnV6 posted:

When code is "on the cob," formerly ring0,

loving :lol:

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE

Blotto Skorzany posted:

Oh no, the cancer has spread to signal processing textbooks! :ohdear:



I guess I don't see how we got from "a square matrix used to convolve an image" to "an arbitrary program executed on a GPGPU processor". One refers to data processed by a program (fixed pipeline or no), the other refers to the program itself. The convolution operation is the same no matter what matrix you feed it.

I guess it's not a horror since different kernels do different things, but it's not quite the same thing. You're basically calling a matrix a function because different matrixes produce different results when you stick them inside some other operation. Except in this case it's the other way around, the term "kernel" in the convolution sense was there first, and later appropriated.

Unless it comes out of GPGPU originally being a hack of the FF pipeline. Did people write GPGPU programs using convolution kernels rendering onto a bitmap or something like that? I know they did with shaders...

Paul MaudDib fucked around with this message at 02:21 on Oct 18, 2014

QuarkJets
Sep 8, 2008

Paul MaudDib posted:

I guess I don't see how we got from "a square matrix used to convolve an image" to "an arbitrary program executed on a GPGPU processor". :words:

Like many words, the word 'kernel' has different meanings depending on context. In image processing, a kernel is basically any operation that gets applied to an entire image or stack of images. CUDA is using the term 'kernel' in the image processing context.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
"'Cause you know sometimes words have two meanings."
    — Led Zeppelin

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
The GPU concept is called a kernel because it is the core, most important part of a vectorized loop. These kernel operations are looped down and around an image just like kernels of corn are looped down and around the cob.

And sometimes the kernel inside these loops is even a convolution kernel. It works in multiple ways!

Adbot
ADBOT LOVES YOU

ATM Machine
Aug 20, 2007

I paid $5 for this
Coding horrors: It is a corn analogy

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