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
Zombywuf
Mar 29, 2008

Ryouga Inverse posted:

he claims his "creates" money, too, which is interesting

Does that mean we can blame him for the recession?

Better fetch my broom.

Adbot
ADBOT LOVES YOU

TheSleeper
Feb 20, 2003

Ryouga Inverse posted:

he claims his "creates" money, too, which is interesting

Hey, who doesn't want a magic money creating black box? I know I sure as hell would like one.

Bozart
Oct 28, 2006

Give me the finger.

TheSleeper posted:

Hey, who doesn't want a magic money creating black box? I know I sure as hell would like one.

Sometimes it kills you though.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I have to fix a few of these every year (hint: guess why it comes up once a year). This is for initializing date/time pickers on windows/web forms using VB.net to by default show a report that spans from a month ago to today:

code:

StartDate.Value = New Date(Now().Year, Now().Month – 1, 1, 0, 0, 0)

nullfox
Aug 19, 2008

Scaramouche posted:

I have to fix a few of these every year (hint: guess why it comes up once a year). This is for initializing date/time pickers on windows/web forms using VB.net to by default show a report that spans from a month ago to today:

code:

StartDate.Value = New Date(Now().Year, Now().Month – 1, 1, 0, 0, 0)


Is it because Month is 0 indexed, and in January the result of (Now().Month - 1) is -1?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

WildFoxMedia posted:

Is it because Month is 0 indexed, and in January the result of (Now().Month - 1) is -1?

Close, but not quite. It's more that January (1) - 1 = 0. I had to switch them all to using the in-built date.AddMonths(-1) so it would roll under/over properly.

Kelson
Jan 23, 2005

Scaramouche posted:

Close, but not quite. It's more that January (1) - 1 = 0. I had to switch them all to using the in-built date.AddMonths(-1) so it would roll under/over properly.

Or use (Now().Month + 10)%12+1, but that won't help with the wrong year... and includes the dreaded modulus!

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
I just inherited a codebase where the previous developer had something of a mid-life crisis and disappeared off the face of the earth when it was "about 90%" done.












Not only is it actually probably that close to done, but the code actually looks like it was written by someone who knew what they were doing.

I'm sure I will find a giant coding horror in here somewhere to whack me upside the head, but so far the only one has been that he didn't know that static classes can have constructors.

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

Ryouga Inverse posted:

Not only is it actually probably that close to done, but the code actually looks like it was written by someone who knew what they were doing.

I'm sure I will find a giant coding horror in here somewhere to whack me upside the head, but so far the only one has been that he didn't know that static classes can have constructors.

Or maybe he realised that static class constructors are the real horror?

UberJumper
May 20, 2007
woop
Ohgod :psyduck:

code:
    return ''.join(map(lambda x: str(x[0]), [(len(list(group)), name) for name,
      group in itertools.groupby(
        ''.join(map(str, map(lambda x: x + 1, self.data)))
        )
      ]))
This converts a list of 1 and -1's into RLE string.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Milotic posted:

Or maybe he realised that static class constructors are the real horror?

What's wrong with them? I mean, you can't/shouldn't put any logic in them that depends on the state when they're called, but if all you're doing is making a class with a bunch of constant data in it that can't be constructed through basic initializers, what's wrong with it?

The alternative is having some retarded InitializeConstants() call that has to be done in a bunch of different places.

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

Ryouga Inverse posted:

What's wrong with them? I mean, you can't/shouldn't put any logic in them that depends on the state when they're called, but if all you're doing is making a class with a bunch of constant data in it that can't be constructed through basic initializers, what's wrong with it?

The alternative is having some retarded InitializeConstants() call that has to be done in a bunch of different places.

You can get into headaches if your static constructors reference other static classes with their own static constructors. Also in .NET at least, you have no control over when it executes. And if the constructor throws an exception, it will not and cannot be called again, and then your app domain is a bit hosed.

I'd rather use some form of factory / singleton pattern, and perform the initialisation either when the method is first accessed, or just at the start of the application/main loop/whatever. At least you can re-call your setup code if an exception occurs.

Infinite Recursion
Mar 26, 2008

Try this trick and spin it, yeah
Your head will collapse
But there's nothing in it
Two instances that made us want to throw our computers out the window in frustration (both Java):

Mine:
code:
while (x < someVal);
{
    someFunction(params);
    x++;
}
And another from a friend (these forums' VorpalBlade):
code:
func(val)
{
    if(!recursion_stop);
    {
        func(val + 1);
    }
    return;
}
At least he got a stack overflow to indicate what was going wrong with his; mine just continued happily executing forever. Took us hours to figure out the problem, and the simplicity of the solution made it even worse. :bang:

RussianManiac
Dec 27, 2005

by Ozmaugh
I don't get it. Did someVal or x get affected by someFunction call?

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"

RussianManiac posted:

I don't get it. Did someVal or x get affected by someFunction call?

This is an infinite loop:

code:
int x = 0;
while (x == 0);
{
  x = 1;
}

Infinite Recursion
Mar 26, 2008

Try this trick and spin it, yeah
Your head will collapse
But there's nothing in it

RussianManiac posted:

I don't get it. Did someVal or x get affected by someFunction call?

It's even simpler than that.

Look at the semicolons

DoctorTristan
Mar 11, 2006

I would look up into your lifeless eyes and wave, like this. Can you and your associates arrange that for me, Mr. Morden?

Infinite Recursion posted:

It's even simpler than that.

Look at the semicolons

Well that's what you get for using Allman style :colbert:

Standish
May 21, 2001

DoctorTristan posted:

Well that's what you get for using Allman style :colbert:
what you get for not using -Wextra you mean.

edit: actually -Wextra will only warn for empty if/else/do-while loops, never mind me.

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

Standish posted:

what you get for not using -Wextra you mean.

edit: actually -Wextra will only warn for empty if/else/do-while loops, never mind me.

http://peter.hates-software.com/2004/08/20/6550cefa.html

GCC's option flags are a horror, although of lesser magnitude than GCC's internals and much of glibc

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

Otto Skorzeny posted:

http://peter.hates-software.com/2004/08/20/6550cefa.html

GCC's option flags are a horror, although of lesser magnitude than GCC's internals and much of glibc

hey it's the elvis operator!

RussianManiac
Dec 27, 2005

by Ozmaugh

Infinite Recursion posted:

It's even simpler than that.

Look at the semicolons

Ohh, didn't notice that. That would be frustrating to fix assuming I had a habit of ending while loops with ;

Troglepus
Jan 10, 2007
A man for all and none.

Code posted:

/// <summary>
/// Gets the HashCode for the object
/// </summary>
/// <returns>Returns an integer HashCode</returns>
public override int GetHashCode()
{
string TypeAndID = string.Format("{0}~+~+~{1}", this.GetType().FullName, this.ID);
return TypeAndID.GetHashCode();
}

/// <summary>
/// Tests validity of passed object
/// </summary>
/// <param name="obj"></param>
/// <returns>Returns boolean: false of passed object is null, otherwise result of testing object's HashCode</returns>
public override bool Equals(object obj)
{
IBaseObject bobj = obj as IBaseObject;

if (bobj == null) { return false; }

return this.GetHashCode() == bobj.GetHashCode();
}
:bang:

Infinite Recursion
Mar 26, 2008

Try this trick and spin it, yeah
Your head will collapse
But there's nothing in it

DoctorTristan posted:

Well that's what you get for using Allman style :colbert:

I like my clearly-defined starting and ending points for blocks of code :colbert:

ColdPie
Jun 9, 2006

Infinite Recursion posted:

I like my clearly-defined starting and ending points for blocks of code :colbert:

Ever heard of indentation?

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

Infinite Recursion posted:

I like my clearly-defined starting and ending points for blocks of code :colbert:

code:
if (foo) {
     bar();
     while (baz) {
          fred();
     }
}
Clearly defined enough for me, clearly defined enough for vim that I can bounce on the % key when it's three in the afternoon, dunno what your major malfunction is

Infinite Recursion
Mar 26, 2008

Try this trick and spin it, yeah
Your head will collapse
But there's nothing in it
Eh, I don't really mind either method; indentation is more than enough for me, I was just taught to use the Allman style, and haven't bothered to change that habit. I've even considered going to Python style*, so that the only (efficient) way to distinguish blocks of code is through indentation.


*i.e.:
code:
for (i = 0; i < 10; i++) {
     if(i % 2 == 0) {
         doSomething(i); }
     else {
         doSomethingElse(i); } }

Infinite Recursion fucked around with this message at 23:55 on Feb 23, 2010

ColdPie
Jun 9, 2006

Infinite Recursion posted:

Eh, I don't really mind either method; indentation is more than enough for me, I was just taught to use the Allman style, and haven't bothered to change that habit. I've even considered going to Python style*, so that the only (efficient) way to distinguish blocks of code is through indentation.


*i.e.:
code:
for (i = 0; i < 10; i++) {
     if(i % 2 == 0) {
         doSomething(i); }
     else {
         doSomethingElse(i); } }

If I ever saw someone using this in practice, I'd probably post it in this thread.

Sebbe
Feb 29, 2004

ColdPie posted:

If I ever saw someone using this in practice, I'd probably post it in this thread.

I have seen students do this in practice (albeit without proper indentation).

Either you do grouping by indentation or you do grouping by braces; both look fine, but by god, taking grouping by indentation and appending braces to make it balance out makes it look like an afterthought.

Infinite Recursion
Mar 26, 2008

Try this trick and spin it, yeah
Your head will collapse
But there's nothing in it

ColdPie posted:

If I ever saw someone using this in practice, I'd probably post it in this thread.

I'll never actually use it, of course, but it had been a consideration when I started learning Python (this was before I realised that using one language's standards for another is a terrible idea).

fankey
Aug 31, 2001

ColdPie posted:

If I ever saw someone using this in practice, I'd probably post it in this thread.
One of my first tasks as an intern many years ago was dealing with a 5k+ line source file that some 'smart guy' programmed exactly in this way. It's really fun when you just want to comment out doSomething in the example above. This was before there were any tools ( at least that I was aware of ) for automatically reformatting code. The indention craziness was just one of the horrors involved in that file.

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

fankey posted:

One of my first tasks as an intern many years ago was dealing with a 5k+ line source file that some 'smart guy' programmed exactly in this way. It's really fun when you just want to comment out doSomething in the example above. This was before there were any tools ( at least that I was aware of ) for automatically reformatting code. The indention craziness was just one of the horrors involved in that file.

Why oh why do the children not learn to unix in school :negative:

indent(1) for the uninitiated

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Otto Skorzeny posted:

Why oh why do the children not learn to unix in school :negative:

indent(1) for the uninitiated
ntaylor@li85-191:~$ man indent
No manual entry for indent


:negative: :respek: :negative:


edit: o it's in osx though :shobon:

Dijkstracula fucked around with this message at 06:21 on Feb 24, 2010

Sewer Adventure
Aug 25, 2004

Dijkstracula posted:

ntaylor@li85-191:~$ man indent
No manual entry for indent


:negative: :respek: :negative:


edit: o it's in osx though :shobon:

code:
~% sudo port install indent
--->  Computing dependencies for indent
--->  Fetching indent
--->  Attempting to fetch indent-2.2.10.tar.gz from [url]http://www.mirrorservice.org/sites/ftp.gnu.org/gnu/indent[/url]
--->  Verifying checksum(s) for indent
--->  Extracting indent
--->  Applying patches to indent
--->  Configuring indent
--->  Building indent
--->  Staging indent into destroot
--->  Installing indent @2.2.10_0
--->  Activating indent @2.2.10_0
--->  Cleaning indent
~% 

Munkeymon
Aug 14, 2003

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



Dijkstracula posted:

edit: o it's in osx though :shobon:

Not on our OSX machines here at work :(

Pardot
Jul 25, 2001




Sewer Adventure posted:

code:
~% sudo port install indent
--->  Computing dependencies for indent
--->  Fetching indent
--->  Attempting to fetch indent-2.2.10.tar.gz from [url]http://www.mirrorservice.org/sites/ftp.gnu.org/gnu/indent[/url]
--->  Verifying checksum(s) for indent
--->  Extracting indent
--->  Applying patches to indent
--->  Configuring indent
--->  Building indent
--->  Staging indent into destroot
--->  Installing indent @2.2.10_0
--->  Activating indent @2.2.10_0
--->  Cleaning indent
~% 

Everyone is using brew now instead of port :ssh:

fankey
Aug 31, 2001

Otto Skorzeny posted:

Why oh why do the children not learn to unix in school :negative:

indent(1) for the uninitiated
Children? This was on Windows 3.11 ( for workgroups! ). Unfortunately my machine wasn't one that was blessed with a modem to reach the outside world - perhaps I could have posted to alt.reformat.my.code.please if it was.

Sewer Adventure
Aug 25, 2004

Pardot posted:

Everyone is using brew now instead of port :ssh:

:o:

FateFree
Nov 14, 2003

I had to post this. I've seen a lot of lovely code in my day, but this is hands down the worst method I've ever seen written in my life. This simple method shows such a misunderstanding of the basic principles of coding with Java and coding in general.

The method in question is in a utility to format Strings or something.

code:
public static String convertLongObjectToString(Object value) {
    return String.valueOf((Long)value);
}
Yes brilliant. Lets see how this is being called.

code:
public void setDataValue(Object value) {
   this.setId(DataFormatHelper.convertLongObjectToString((Object)value)
}
I don't even know where to begin. Its almost so ridiculous that I feel like maybe I'm missing something. Not many methods have the ability to make you somehow feel dumber by association.

RussianManiac
Dec 27, 2005

by Ozmaugh
What's wrong with that, brah, haven't you ever herd of polymorphism?

Adbot
ADBOT LOVES YOU

markerstore
Dec 5, 2003
Canny!

RussianManiac posted:

What's wrong with that, brah, haven't you ever herd of polymorphism?

it's static "brah"

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