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
Dylan16807
May 12, 2010
https://perl6advent.wordpress.com/2017/12/01/the-grinch-of-perl-6-a-practical-guide-to-ruining-christmas/

:stonklol:

Adbot
ADBOT LOVES YOU

ChubbyThePhat
Dec 22, 2006

Who nico nico needs anyone else

lmao oh god

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

This mostly looks like any language that lets you modify internals, combined with "Perl 6 looks kind of strange".

Kazinsal
Dec 13, 2011



Nope. :stonkhat:

JawnV6
Jul 4, 2004

So hot ...

Coffee Mugshot posted:

I mean, the idea is reasonable.
It really isn't.

Coffee Mugshot posted:

I assume you would write a huge standard library for your language in Rust and then just have your compilation frontend generate some intermediate code that calls those library functions after you take all the expressions in your languages and massage them into Rust code. The generated code would probably be very little in comparison to the size of the existing Rust stdlib that people can actually read and write and use nice tools for. Debugging Rust code would probably be a lot easier than debugging LLVM IR's SSA code in terms of the tooling in place. And well, Rust generates LLVM IR anyways. It seems like it'd be nice not to reimplement the borrow checking logic in your language if you take advantage of an intermediary target that becomes LLVM IR anyways.

If I was writing a new "memory-safe" language, this could be an easier start than actually using LLVM.
Here's one massive problem space that's being introduced: So rather than writing a Blub compiler to LLVM, I'm going to write a Blub compiler/transpiler/something to Rust, that's then compiled to LLVM. What happens when I write an error in Blub that's caught at the Rust layer? Are you building another magic system that back-propogates Rust-level errors into Blub? Is that generic enough to handle LLVM-layer errors and point all the way back to the Blub source line as well?

You're not getting the Rust feature set for "free," you're getting an extra layer potential of bugs. By the time you're down at LLVM, getting a reasonable error to bubble back up to the original un-mangled source is just exhausting levels of hand waving.

comedyblissoption
Mar 15, 2006

I imagine in a finalized rust is LLVM world, you would let rust compile to assembly on the target platform instead of using LLVM as an intermediary. Of course, such an enterprise would be an immense undertaking.

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
Many thanks. This may be just the thing that gets me to playing with Perl6. Previous glances have been quickly aborted because they've ripped out so many of the things that make Perl so great.

Hughlander
May 11, 2005

JawnV6 posted:

It really isn't.

Here's one massive problem space that's being introduced: So rather than writing a Blub compiler to LLVM, I'm going to write a Blub compiler/transpiler/something to Rust, that's then compiled to LLVM. What happens when I write an error in Blub that's caught at the Rust layer? Are you building another magic system that back-propogates Rust-level errors into Blub? Is that generic enough to handle LLVM-layer errors and point all the way back to the Blub source line as well?

You're not getting the Rust feature set for "free," you're getting an extra layer potential of bugs. By the time you're down at LLVM, getting a reasonable error to bubble back up to the original un-mangled source is just exhausting levels of hand waving.

This is basically how we did C++ in University. There was some C++ to C transpiler that than compiled C with the HPUX 6.X C toolchain. Debugging compiler or worse run time errors were an exercise in frustration.

Coffee Mugshot
Jun 26, 2010

by Lowtax

JawnV6 posted:

It really isn't.

Here's one massive problem space that's being introduced: So rather than writing a Blub compiler to LLVM, I'm going to write a Blub compiler/transpiler/something to Rust, that's then compiled to LLVM. What happens when I write an error in Blub that's caught at the Rust layer? Are you building another magic system that back-propogates Rust-level errors into Blub? Is that generic enough to handle LLVM-layer errors and point all the way back to the Blub source line as well?

You're not getting the Rust feature set for "free," you're getting an extra layer potential of bugs. By the time you're down at LLVM, getting a reasonable error to bubble back up to the original un-mangled source is just exhausting levels of hand waving.

I also don't think you get the Rust feature set for free, it's a trade-off. Source mapping and error propagation are always frustrating to get right when writing a transpiler, which is a good enough reason to target gimple and LLVM IR. At the same time, debugging LLVM IR and gimple is largely frustrating in and of itself and could benefit from better tools. Are better tools worth investing in if the resulting toolchain is fragile?

Foxfire_
Nov 8, 2010

I figured the target is more 'I am doing research on compiler/language design and am implementing something for a paper", not "I am writing production code"

So most of your work and bugs would be in compiler you're writing of in the input code you're feeding it. Debugging your compiler emitting bad Rust is probably easier than debugging it emitting bad LLVM or C and all you're really trying to show is that some basic concept is interesting/feasible.

DELETE CASCADE
Oct 25, 2017

i haven't washed my penis since i jerked it to a phtotograph of george w. bush in 2003

Foxfire_ posted:

Debugging your compiler emitting bad Rust is probably easier than debugging it emitting bad LLVM

what makes you think so? the llvm intermediate representation was explicitly designed for compilers to emit, while the rust programming language was not

Coffee Mugshot
Jun 26, 2010

by Lowtax

DELETE CASCADE posted:

what makes you think so? the llvm intermediate representation was explicitly designed for compilers to emit, while the rust programming language was not

Well, I think the value of LLVM IR is the ease of adding or taking advantage of optimization transformations if you can generate reasonable code like https://llvm.org/docs/LangRef.html#type-system mentions. I don't know, it depends on this theoretical language you're implementing a compiler for, I suppose. I think it's non-trivial to map non-C like languages to LLVM's type system and wouldn't mind stealing some of the work of another similar language frontend that's close enough to my language. That's all I'm saying when I claimed it was not unreasonable to desire something like this. Is Rust the language for it? Probably not like that article says.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Using an intermediate representation that enforces strong formation rules can be invaluable in a compiler. However, it is really difficult to generate source code that is structured even vaguely idiomatically unless your source language is basically a minor superset of the target language. Rust trades extremely heavily on the scope structure of the source, so it's very hard for me to imagine what language could be usefully transformed into Rust code.

Ranzear
Jul 25, 2013

iospace posted:

BITWISE OPERATIONS MOTHER FUCKER, DO YOU KNOW THEM

"Can your API just send me an array of booleans instead of an int?"

"Don't you have to initialize the bit before you can shift to it?"

"Are you sure a MySQL BLOB can store enough quest flags?"

:negative:

I exaggerate, but still...

Ranzear fucked around with this message at 22:55 on Dec 3, 2017

feedmegin
Jul 30, 2008

Hughlander posted:

This is basically how we did C++ in University. There was some C++ to C transpiler that than compiled C with the HPUX 6.X C toolchain. Debugging compiler or worse run time errors were an exercise in frustration.

Cfront, the original C++ compiler, compiled to C yeah. They don't do that any more for a reason.

Xarn
Jun 26, 2015
Student code is cheating but still

C++ code:
    if (str != "") {
        const char* charp = str.c_str();
        if (insert_node(charp, *m_root)) {
 
        }
        else {
            m_size++;
            return true;
        }
    }
C++ code:
    bool isErased = false;
    if (str != "") {
        const char* sptr = str.c_str();
        isErased = delete_node(sptr, *m_root);
        if (!isErased) {
 
        }
        else {
            m_size--;
        }
    }
C++ code:
    if (*charp) {
        if (!node.children[*charp]) {
            return false;
        }
        else {
            trie_node* tnode = node.children[*charp];
            return delete_node(++charp, *tnode);
        }
    }
    else if (node.is_terminal == false) {
 
    }
    else {
        node.is_terminal = false;
        return true;
    }
    return false;
imagine 600 more lines of this... trying to help him find bugs is one of the most mind-bending things I've done :v:

Munkeymon
Aug 14, 2003

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



Wouldn't a compiler that emits valid Rust have to pretty much re-implement enough of the borrow checker to basically be the Rust compiler with a different lexer?

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

Xarn posted:

Student code is cheating but still

C++ code:
imagine 600 more lines of this... trying to help him find bugs is one of the most mind-bending things I've done :v:

Just gotta take it one line at a time... just watching a debugger do each baby step until they can't verbally justify to you why one of them took place...

Trying to just look at the whole code and explain to them the issue has no hope. It does take forever to walk them through it by hand and can be a real slog when a dozen students are lined up. At my school, running the office hours room for intro to programming is often compared to being a triage doctor in a war zone.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.
"Rule RequireUpperBoundDeps failed with message:" followed by like 10 pages of dependency trees

Kill me now.

Xik
Mar 10, 2011

Dinosaur Gum
C# code:
result = someServiceCall();

if (result != null)
{
    return result
}

return null;
:thunk:

(It's pretty tame but it's all I got recently, since quite a lot of my work has been greenfield. Aka, generating horrors.)

Eela6
May 25, 2007
Shredded Hen

Xik posted:

C# code:
result = someServiceCall();

if (result != null)
{
    return result
}

return null;
:thunk:

(It's pretty tame but it's all I got recently, since quite a lot of my work has been greenfield. Aka, generating horrors.)

ah, go#

ChickenWing
Jul 22, 2010

:v:

My linter slows my computer the gently caress down because I have it constantly re-analyzing my code, but I honestly don't mind because it's kept me from making stuff like that a non-trivial number of times.

I'm still embarrassed that an if(date.compareTo(otherDate) == 0) made it into a PR :(

Workaday Wizard
Oct 23, 2009

by Pragmatica

ChickenWing posted:

I'm still embarrassed that an if(date.compareTo(otherDate) == 0) made it into a PR :(

what’s wrong with it?

Bonfire Lit
Jul 9, 2008

If you're one of the sinners who caused this please unfriend me now.

Shinku ABOOKEN posted:

what’s wrong with it?
.equals exists.

Pollyanna
Mar 5, 2005

Milk's on them.


Xik posted:

C# code:
result = someServiceCall();

if (result != null)
{
    return result
}

return null;
:thunk:

(It's pretty tame but it's all I got recently, since quite a lot of my work has been greenfield. Aka, generating horrors.)

Trying to figure out why this would be necessary. Side effect of evaluating result != null possibly???
Other than that, no reason not to just return someServiceCall().

Thermopyle
Jul 1, 2003

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

Pollyanna posted:

Trying to figure out why this would be necessary. Side effect of evaluating result != null possibly???
Other than that, no reason not to just return someServiceCall().

This is the coding horrors thread, not the "this looks weird but is necessary" thread.

hailthefish
Oct 24, 2010

My money's on 'writing without thinking' rather than some weird-but-necessary magic.

Not quite as hilariously pointless as "if (thing == true) return true else return false", but very close.

hailthefish fucked around with this message at 14:46 on Dec 6, 2017

Hughlander
May 11, 2005

"I need a place to put a breakpoint to inspect result in the rare case it's not NULL."

boo_radley
Dec 30, 2005

Politeness costs nothing

Hughlander posted:

"I need a place to put a breakpoint to inspect result in the rare case it's not NULL."

"You can't see the debugging code I deleted from this function"

FlapYoJacks
Feb 12, 2009
I spent the last 15 days cleaning up the code of our biggest application.

In total:
- Over 500 variable names where straight up changed to be readable (IE: a -> accounts)
- All of the variables were standardized for capitalization, as they were all loving random, to begin with.
(IE: Some variables began with a capital, some not, some were camel case, some not, some were descriptive, some were a combination of descriptive and shorthand, etc etc)
- The previous dev had all of the class names start with a _ and then had a typedef pointing to the class without a _, thus hiding if the function argument was a pointer or not.
Example:
C++ code:
class _myclass{ }
typedef _myclass *myclass;
I ripped all of that bullshit out and just passed the god drat function pointers if they were needed. Hiding it just made me see red.

- There were almost no function pointers. Instead, the previous developer decided to have 6 listeners all in their own separate threads that the various classes talked to. I removed all but one of them in favor of function pointers without any ill effects.
- Previously there was just two folders: src and inc. Now there are multiple folders.
- I added 6 new cpp/h files in an attempt to break up a single file that was over 3,000 lines long.
- Namespaces are a now a thing.
- The one class that was using a namespace was extending std.
- I removed all of the "using namespace std" lines everywhere.
- The last thread had a usleep(100) in it. Changing that to a msleep(250) had no ill effects and made processor usage go from 20% to 0% at idle. :v:
- A SUPERCLASS DEPENDED ON A SUBCLASS OF ITSELF. When I saw that I drat near had an aneurysm.

The sheer amount of stupidity in this code was staggering. That list is just a few of the big ones I remember. The merge request was over 5,000 lines of code changed. :suicide:

Hughlander
May 11, 2005

boo_radley posted:

"You can't see the debugging code I deleted from this function"

I’m not saying it’s good, but I have written code like that for Android NDK code and I may even have left it in place at one point or another. Anything past -O0 will do the right thing anyway. But yes it’s a horror to see in production code and to me means that people don’t diff what they’re checking in.

The Phlegmatist
Nov 24, 2003

hailthefish posted:

Not quite as hilariously pointless as "if (thing == true) return true else return false", but very close.

These get posted every once in a while in this thread and I'm like 95% sure it's people who learned to program using Perl, since ca. Perl 5 and Perl Best Practices that was a common idiom to guarantee you returned a boolean value and not something else.

e: along with return (var? || false)

The Phlegmatist fucked around with this message at 15:52 on Dec 6, 2017

Athas
Aug 6, 2007

fuck that joker

ratbert90 posted:

- A SUPERCLASS DEPENDED ON A SUBCLASS OF ITSELF. When I saw that I drat near had an aneurysm.

How does this work in C++? Is this some shenanigans with forward-declared classes that just end up not causing a linker/compiler error by chance (because of no data members?)?

Athas fucked around with this message at 22:59 on Dec 6, 2017

FlapYoJacks
Feb 12, 2009

Athas posted:

How does this work in C++? Is this some shenanigans with forward-declared classes that just end up not causing a linker/compiler error by change (because of no data members?)?

Pretty much!

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

ratbert90 posted:

The sheer amount of stupidity in this code was staggering. That list is just a few of the big ones I remember. The merge request was over 5,000 lines of code changed. :suicide:

But all the tests passed, right, so you know nothing broke, right?

ChickenWing
Jul 22, 2010

:v:

Factor Mystic posted:

But all the tests passed, right, so you know nothing broke, right?

in before "what tests?"

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

Key to making a large change like that -- disable the tests with 1 line somewhere in the middle.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

boo_radley posted:

"You can't see the debugging code I deleted from this function"

This kind of thing is why I always review my changes before sending out for review. Preferably with a night's sleep in between authoring and reviewing, too.

FlapYoJacks
Feb 12, 2009

ChickenWing posted:

in before "what tests?"

More like upper management going: "Test? We have always done it without unit tests."

Adbot
ADBOT LOVES YOU

Doom Mathematic
Sep 2, 2008

boo_radley posted:

"You can't see the debugging code I deleted from this function"

This is going to be it, or something similar. Or there was logic just before return result; or there was logic just before return null; which was removed some time back. It's much easier to accidentally refactor into that state than it is to write it out directly.

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