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
LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

The Laplace Demon posted:

The code in all it's glory.
At least it's not Fortran? :suicide:

Leaving aside the quadruple pointer, the most infuriating thing about this is the attitude of "hey guys my code don't work! here it is whats wrong?"

Adbot
ADBOT LOVES YOU

..btt
Mar 26, 2008

Smugdog Millionaire posted:

What's this use case where you can tolerate occasionally incorrect multiplication as long as you know exactly how long it will take?

This is from a while ago, but I believe it's part of a filter to reduce hysteresis for a real-time weighing scale (truck drives over scale without stopping, weight is logged). I think they're slowly being replaced by far more powerful hardware and higher level languages (like C :v:) for the drivers, but in the meantime it'll probably keep my dad in work until he retires, since he's one of like 10 people worldwide who have experience with the older hardware and are still working.

EAT THE EGGS RICOLA
May 29, 2008

Incursion is a roguelike that is quite good (and buggy) that is being opened up by the developer

It's beautiful.

it is
Aug 19, 2011

by Smythe
How not to write a method header:
code:
def etl(h, p, u, k, d, H, P, U, K, D):

Westie
May 30, 2013



Baboon Simulator

it is posted:

How not to write a method header:
code:
def etl(h, p, u, k, d, H, P, U, K, D):

I take it that arguments are passed to the function twice, but the 2nd time it's all in upper case?

it is
Aug 19, 2011

by Smythe
They are not the same variable. They are related, but different variables. Apparently 1-word arguments are acceptable.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
They are not acceptable.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



For a company that involves specialized software for every facet of it's business, the company I work for is really poo poo at actually developing software.

Oops looks like someone was making changes three months back and the thing they were doing didn't work at all, why bother fixing it up after you've done the work and have it moved to production? Let's just leave it sitting in Sourcesafe where its hard to tell if something at least a month old is in production or not from looking at the history and it might get accidentally carried in to production from another change.

Oops turns out it was something incredibly simple to catch if we had any automated testing like a barcode on a printed document not being up to the specification or even just not being there at all

Too bad we don't have a QA department, wait poo poo we do but they're not interested in developing any actual methods or automated procedures that can catch something as simple as a barcode being wrong.

Nope, they'll make you wait days for your change to be deployed to production while they do other things though, or they'll make you wait all that time and then reject you on a minor issue that doesn't affect any customers and that they'll admit had nothing to do with your change. Time to have our waterfall-y process take a half day to a day to have the change moved back to them so they can sit on it for another couple of days until they reject it for whatever the hell they want that they didn't tell you about before.

It's bizarre going online and reading about software development that involves modern version control and dependency injection or inversion of control or agile methods while this place doesn't even have the notion of a unit test.

baquerd
Jul 2, 2007

by FactsAreUseless

it is posted:

How not to write a method header:
code:
def etl(h, p, u, k, d, H, P, U, K, D):

You sure you aren't looking at obfuscated code? Maybe someone copied something off the web that was obfuscated.

Foxfire_
Nov 8, 2010

I'm guessing ported fortran linear algebra library.

Pythagoras a trois
Feb 19, 2004

I have a lot of points to make and I will make them later.
I'd like to think the lowercase letters are the slugs of the upper case letters. etl is an abbreviation for "eat the lazy".

it is
Aug 19, 2011

by Smythe
Etl = export, transform, load. Basically copying from one kind of database to another. I have no idea how the sets of arguments are different from each other. They are called from the command line, and this method only uses the capital ones, and ignores the lowercase ones. Some of them use all of them and some of them use only the lowercase ones. Some of them include only the variables they use, some include all of them. It was written by a human. It builds a SQL query to populate SQL database tables from NoSQL database connections. Fun!

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



I saw a homemade bubble sort implementation in a production application today, I'm going to go out on a limb and say that VB.NET has a built in sorting function and one that is a fair bit better than bubble sort.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

piratepilates posted:

I saw a homemade bubble sort implementation in a production application today, I'm going to go out on a limb and say that VB.NET has a built in sorting function and one that is a fair bit better than bubble sort.

It does and it is.

kitten smoothie
Dec 29, 2001

PHP with lambdas, generics, and type checking. Oh my!

http://hacklang.org/

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
PHP didn't have lambdas already?

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Found deep in a decompiled Microsoft.SharePoint.Linq assembly:

C# code:
internal static string GetUniqueName(string name, IEnumerable<string> names)
{
    int num = 0;
    string str1 = name;
    try
    {
        while (Enumerable.Contains<string>(names, str1))
        {
            string str2 = num.ToString((IFormatProvider) CultureInfo.InvariantCulture);
            if (name.Length + str2.Length > 128)
                name = name.Substring(0, 128 - str2.Length);
            str1 = name + str2;
            ++num;
        }
    }
    catch (OverflowException ex)
    {
        throw new InvalidOperationException(
            Resources.GetString("CannotConvertNameToValidIdentifier", new object[1]
            {
                (object) name
            }));
    }
    return str1;
}
Nevermind that an OverflowException will only get thrown if we're in a checked context, but to even get to an overflow at all you'll have to get num past 2 billion. Getting to that point requires that you have at least 2 billion unique strings in names. Plus, since it's using Enumerable.Contains, we'll have to enumerate those 2 billion strings 2 billion times before we ever get to a point where it overflows (which it probably won't do anyway since it's unlikely to be in a checked context).

Plorkyeran
Mar 22, 2007

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

Otto Skorzeny posted:

PHP didn't have lambdas already?

5.3 finally added anonymous functions, but the syntax is hilariously verbose since you have to explicitly capture variables.

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

Plorkyeran posted:

5.3 finally added anonymous functions, but the syntax is hilariously verbose since you have to explicitly capture variables.

I'm impressed. Training wheels without the bike indeed.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Otto Skorzeny posted:

I'm impressed. Training wheels without the bike indeed.

Unicycle?

Seems like Facebook has some supersmart people who cannot move off PHP for legacy reasons. PHP with types and the same 'near-instant' reload time sounds pretty cool though.

Although I am looking at the code and I have no idea why it is, "public function foo(): string" with the type defined after the function name, when everything else is, "public string $bar = 'hello world';" I guess it is following the tradition of PHP not being consistent with its naming?

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Otto Skorzeny posted:

I'm impressed. Training wheels without the bike indeed.

And you have to explicitly use references if you want to actually close over the variables rather than just copy them at "closure"-construction time. Hack's lambdas have the same copying semantics, but they're at least more concise about it.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Strong Sauce posted:

Seems like Facebook has some supersmart people who cannot move off PHP for legacy reasons. PHP with types and the same 'near-instant' reload time sounds pretty cool though.

PHP has some underappreciated virtues; Keith Adams gave an interesting talk on this topic a little while ago. But even before Hack, what we wrote in at Facebook didn't feel like writing PHP anywhere I'd done it before. The generators alone made for a pretty big shift when working with asynchronous operations like data access.

quote:

Although I am looking at the code and I have no idea why it is, "public function foo(): string" with the type defined after the function name, when everything else is, "public string $bar = 'hello world';" I guess it is following the tradition of PHP not being consistent with its naming?

The Hack site discusses it a bit: http://docs.hhvm.com/manual/en/hack.annotations.usingtypes.php

hacklang.org posted:

Hack decided to annotate the return types at the end of a function/method declaration instead of near the beginning found in languages like C#. This was done mainly for readability purposes. But there are other reasons to have them positioned the way they are because of closures and searchability. With respect to closures, if the return type is annotated at the beginning of a function, PHP could interpret the return type to be a constant string, thus ignoring the return type altogether. With respect to searchability, searching for "function foo" will produce more useable results than having to use wildcards or some other mechanism to find all the functions named foo(), regardless of return type.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Edison was a dick posted:

I think it was going to be Tcl. There was an article about it on the 20th anniversary of the language, but I can't find it any more.
The best I've got is two paragraphs in http://sdt.bz/31644.

Tcl was roughly the threat, yeah; it was very much tied up in the dynamics of Sun's Java license, which was of course the future of the web at the time. There was an edict to write something that was Java's little brother, or Brendan probably would have made it a little more Lispy. That said, closures and first-class functions and such were pretty high-falutin' for a little-brother language of the day. Improving the language after ES3 became basically impossible due to standards politics and browser market share dynamics, but we managed to push some things into Firefox that are finally coming to ES6 5+ years later.

I love the language, but I've seen more horrible things written in JS than anything else in the last 20 years, for sure. Peril of being accessible and part of computing's most widely deployed platform, I guess, but still...rough on the appetite.

Edit: oy, triple-post. Sorry.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

quote:

With respect to closures, if the return type is annotated at the beginning of a function, PHP could interpret the return type to be a constant string, thus ignoring the return type altogether

what?

Woodsy Owl
Oct 27, 2004

hacklolg posted:

With respect to searchability, searching for "function foo" will produce more useable results than having to use wildcards or some other mechanism to find all the functions named foo(), regardless of return type

edit: I recant. Apparently I'm syntax prejudiced.

Woodsy Owl fucked around with this message at 10:35 on Mar 21, 2014

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
PHP treats unrecognized constants as if they were string literals, because PHP is just that awesome.

PHP code:
php > echo hello;
hellophp > define(hello, 'bye');
php > echo hello;
byephp >

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
byephp

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Woodsy Owl posted:

Or you could not have a retarded syntax and just search for "foo(" or "foo (" :ssh:

Sure, if you want to find all the call sites too, which is usually pretty noisy. This is about finding the function definitions themselves, which is a pretty common task when working with a large system. These guys actually have worked with the language at substantial scale for some time, and they come from pretty solid PL backgrounds. The syntax doesn't really have pieces in it just because they couldn't be bothered to think about it.

Steve French
Sep 8, 2003

Woodsy Owl posted:

Or you could not have a retarded syntax and just search for "foo(" or "foo (" :ssh:

How dare you say that about scala? (Hack is not the first or only language to have this style of function type annotation)

qntm
Jun 17, 2009

Plorkyeran posted:

PHP treats unrecognized constants as if they were string literals, because PHP is just that awesome.

PHP code:
php > echo hello;
hellophp > define(hello, 'bye');
php > echo hello;
byephp >

Perl does this as well. Except sometimes they're treated as subroutine calls.

fritz
Jul 26, 2003

piratepilates posted:

I saw a homemade bubble sort implementation in a production application today, I'm going to go out on a limb and say that VB.NET has a built in sorting function and one that is a fair bit better than bubble sort.

I had a circumstance a few years ago in which a bubble sort was the best choice for the problem.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



fritz posted:

I had a circumstance a few years ago in which a bubble sort was the best choice for the problem.

Please explain in more detail because that sounds very interesting.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

fritz posted:

I had a circumstance a few years ago in which a bubble sort was the best choice for the problem.

I would love to hear more about that circumstance, if only because it sounds like the makings of an awesome interview problem. Were you primarily constrained by code size? Did you get a transaction fee for every swap?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Bubble sort's O(n) on lists where elements are no more than one position out of place, so if you have a very good reason to believe that's the case it can be optimal.

Sebbe
Feb 29, 2004

Subjunctive posted:

I would love to hear more about that circumstance, if only because it sounds like the makings of an awesome interview problem. Were you primarily constrained by code size? Did you get a transaction fee for every swap?

Bubble sort isn't terrible if the list is close to being sorted, i.e. each element isn't too far from its intended location. Probably not terrible on very small inputs, either. (Making quicksort/merge sort use one of the O(n2)-algorithms once they reaches the smaller cases (Think 7-8 elements or fewer; very small inputs) usually should improve performance. I wouldn't be surprised if Bubble sort actually performs decently well in those circumstances.)

Also, there's this, I suppose.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Plorkyeran posted:

Bubble sort's O(n) on lists where elements are no more than one position out of place, so if you have a very good reason to believe that's the case it can be optimal.

I thought insertion was still better in small/mostly-sorted cases, but my theoretical grounding in CS isn't really very strong. I dimly recall that the various JS engines use insertion below a certain element count threshold, but it's been a while since I looked.

Thanks!

..btt
Mar 26, 2008
I guess the more general case where bubble sort is optimal is where long lookups are expensive since you're only comparing adjacent items. That probably will never happen on modern computer hardware. Maybe there'd be some niche application on massively parallel architectures that only have direct access to local memory? But I don't think even that setup is used much anymore.

Xerophyte
Mar 17, 2008

This space intentionally left blank

Subjunctive posted:

I would love to hear more about that circumstance, if only because it sounds like the makings of an awesome interview problem. Were you primarily constrained by code size? Did you get a transaction fee for every swap?

There's the Sweep and Prune algorithm for doing collision detection on animated spatial data. The short description of it is that you sort your object bounds on all 3 axes every frame of your animation and only do detailed collision detection and resolution if a pair of objects have their bounds intersect on all 3. Bubble sort is pretty common here: you can do it while sweeping over the data and the swap operation is exactly when the order of two objects might change and you need to update your potential intersection list.

Plorkyeran
Mar 22, 2007

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

Subjunctive posted:

I thought insertion was still better in small/mostly-sorted cases, but my theoretical grounding in CS isn't really very strong. I dimly recall that the various JS engines use insertion below a certain element count threshold, but it's been a while since I looked.

Thanks!

Insertion sort's a much better choice as the secondary algorithm of a general-purpose sorting algorithm. It's slightly worse in the best-case-for-bubble-sort scenario, and better in most cases.

Adbot
ADBOT LOVES YOU

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

..btt posted:

I guess the more general case where bubble sort is optimal is where long lookups are expensive since you're only comparing adjacent items. That probably will never happen on modern computer hardware. Maybe there'd be some niche application on massively parallel architectures that only have direct access to local memory? But I don't think even that setup is used much anymore.

Apropos the topic of this thread, I bet someone out there is sorting by deleting and inserting rows in a remote database.

They're probably not trying to pick an optimal sort for their use case, though.

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