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
yippee cahier
Mar 28, 2005

Only delay needs to be volatile to implement a timeout, right?

Adbot
ADBOT LOVES YOU

feedmegin
Jul 30, 2008

pokeyman posted:

Parse error at the en dash?

Lexer error surely :colbert:

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
This is what happens when you don't do mandatory code review and let people work on their own.

I found an identical chunk of code repeated 34 times in this (relatively small) project I just inherited. It's not the only chunk of code like that. As far as I can tell, the project's LoC count primarily consists of copy/paste. There are no methods anywhere.

It also has a lot of patterns like:

code:
if (condition) {
 // do stuff
}
else {
  throw some error
}
Instead of
code:
if (!condition) {
  throw some error
}
// do stuff
leading to excessive indentation, since there are no methods:

code:
if (condition) {
  // do stuff
  if (anotherCondition) {
    // you get the idea
    if (yetAnotherCondition) {
      // god have mercy on my soul
    }
    else {
      throw some error
    }
  }
  else {
    throw some error
  }
}
else {
  throw some error
}

I sounded the "technical debt" alarm so we can go back and fix all this poo poo, since it is drat near impossible to read or change without breaking something in the huge nest of conditionals and copy/pasted code.

Pentecoastal Elites
Feb 27, 2007

Munkeymon posted:

The best shared state is none at all

The developer, upon hearing this, was enlightened.

yippee cahier
Mar 28, 2005

New Yorp New Yorp posted:

This is what happens when you don't do mandatory code review and let people work on their own.

I found an identical chunk of code repeated 34 times in this (relatively small) project I just inherited. It's not the only chunk of code like that. As far as I can tell, the project's LoC count primarily consists of copy/paste. There are no methods anywhere.

It also has a lot of patterns like:

code:
if (condition) {
 // do stuff
}
else {
  throw some error
}
Instead of
code:
if (!condition) {
  throw some error
}
// do stuff
leading to excessive indentation, since there are no methods:

code:
if (condition) {
  // do stuff
  if (anotherCondition) {
    // you get the idea
    if (yetAnotherCondition) {
      // god have mercy on my soul
    }
    else {
      throw some error
    }
  }
  else {
    throw some error
  }
}
else {
  throw some error
}

I sounded the "technical debt" alarm so we can go back and fix all this poo poo, since it is drat near impossible to read or change without breaking something in the huge nest of conditionals and copy/pasted code.

I've seen a NMEA sentence parser that did that for every field, separator, etc. The one line else clauses were hundreds of lines away. Thank god we don't have multiple return statements though!

namlosh
Feb 11, 2014

I name this haircut "The Sad Rhino".

Carbon dioxide posted:

.... That said, anyone programming multithreading programs by hand in TYOOL 2018 is asking for disasters, and instead they should just use a good concurrency library of their choice.

...Until you can’t because the rules are too complex to be serviced by the c# Task.Parallel or other libraries.

Then you try to find someone who has multithreaded programming on their resume AND knows what a semaphore and mutex is and fail because the concurrency library is all they know and they’ve never had to deal with dependencies between the data being processed (shared state).

Munkeymon
Aug 14, 2003

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



namlosh posted:

...Until you can’t because the rules are too complex to be serviced by the c# Task.Parallel or other libraries.

Then you try to find someone who has multithreaded programming on their resume AND knows what a semaphore and mutex is and fail because the concurrency library is all they know and they’ve never had to deal with dependencies between the data being processed (shared state).

I haven't needed anything more complicated than Task.Parallel since it came out :shrug:

Khorne
May 1, 2002

namlosh posted:

...Until you can’t because the rules are too complex to be serviced by the c# Task.Parallel or other libraries.

Then you try to find someone who has multithreaded programming on their resume AND knows what a semaphore and mutex is and fail because the concurrency library is all they know and they’ve never had to deal with dependencies between the data being processed (shared state).
Intel's TBB can extend the ground covered by libraries pretty well. I definitely agree with you though, once the task goes beyond concurrency/async/embarrassingly parallel you're on your own even if you use a library to avoid boilerplate.

namlosh
Feb 11, 2014

I name this haircut "The Sad Rhino".

Munkeymon posted:

I haven't needed anything more complicated than Task.Parallel since it came out :shrug:

Tbh, I hadn’t either before my last job. Much like war, Financial Tech puts a man through many changes...

^^^^^^ I’ll have to check out TBB... thanks!

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.
hey everyone, tired of dealing with multiple parameters in methods? tired of trying to figure out what to do with return values? dependency injection a pain in the rear end?

behold:

before
code:
   public Task<AuthorizeResult> LoginAsync( string username, Claims claimList, ....)  {


  ...

    return Task.FromResult(new AuthorizeResult("My result");
   }
after:

code:
   public Task LoginAsync ( LoginAsyncContext context) {
       var username = context.Username;
       var claims = context.ClaimsList;
       
      ...

      context.AuthorizeResult = new AuthorizeResult("My result");
}
i plan on making an entire project where literally every function has one parameter and returns void or Task and seeing how this scales.

LongSack
Jan 17, 2003

It is me, I am the horror.

In my data access layer classes, there are the expected insert/update/delete methods, then a group of Getxxx and Readxxx methods. The Get methods return a List of of objects, the Read methods return a single object. At the core of these methods are private methods that accept a string sql statement and a params array of SqlParameters.

This allows me to do things like
C# code:
public static List<Role> Get() => _get(“select * from Roles order by Description;”)
and
C# code:
public static Role Read(string description ) => _read(“select * from Roles where Description=@d;”, 
new SqlParameter { ParameterName = “d”, SqlDbType = SqlDbType.NVarChar, Value = description})
The _get and _read methods do all the heavy lifting dealing with connections, commands, etc.

Today, after working with this stuff for three years, I just now realized that can use
C# code:
command.Parameters.AddRange(params)
rather than enumerating through the params array. I don’t know whether it makes a difference (for all I know, AddRange enumerates through its parameter), but it sure makes the code cleaner.

Magissima
Apr 15, 2013

I'd like to introduce you to some of the most special of our rocks and minerals.
Soiled Meat

Bruegels Fuckbooks posted:

hey everyone, tired of dealing with multiple parameters in methods? tired of trying to figure out what to do with return values? dependency injection a pain in the rear end?

behold:

before
code:
   public Task<AuthorizeResult> LoginAsync( string username, Claims claimList, ....)  {


  ...

    return Task.FromResult(new AuthorizeResult("My result");
   }
after:

code:
   public Task LoginAsync ( LoginAsyncContext context) {
       var username = context.Username;
       var claims = context.ClaimsList;
       
      ...

      context.AuthorizeResult = new AuthorizeResult("My result");
}
i plan on making an entire project where literally every function has one parameter and returns void or Task and seeing how this scales.
let me guess, all of the "argument" fields are mutable too

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Magissima posted:

let me guess, all of the "argument" fields are mutable too

ding ding

Soricidus
Oct 21, 2010
freedom-hating statist shill
code:
[
    {
        "key": "butts",
        "value": "true"
    },
    {
        "key": "dongs",
        "value": "false"
    }
]

Zopotantor
Feb 24, 2013

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

JawnV6 posted:

You still haven't really explained why you think the timeout author doesn't understand 'volatile'? The declaration for hardware_thing isn't shown, it's presumably done properly and is reaching out to the MMIO every time. But if you don't have 'volatile' on delay/tmo, despite the fact that they reside in "normal" RAM, anything above -O0 is going to wipe out the entire loop.
There are better, safer ways to implement a delay. OK, I did things like this myself, 40 years ago, in BASIC, but I learned the errors of my ways.

redleader
Aug 18, 2005

Engage according to operational parameters

Soricidus posted:

code:
[
    {
        "key": "butts",
        "value": "true"
    },
    {
        "key": "dongs",
        "value": "false"
    }
]

this, then
JavaScript code:

for (var i = 0; i < data.length; i++) {
    if (data[i].key == 'butts') {
        butts = data[i].value;
    }

    if (data[i].key == 'dongs') {
        dongs = data[i].value;
    }

    // etc. some of the values get turned into numbers or bools!
}

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Soricidus posted:

code:
[
    {
        "key": "butts",
        "value": "true"
    },
    {
        "key": "dongs",
        "value": "false"
    }
]

Well obv you can't just use a key value pair for this - some people might have multiple dong values or multiple butt values.

Polio Vax Scene
Apr 5, 2009



But what if I have a tumor on my dong, eh buddy? I'd like to see a key-value pair represent that

Xik
Mar 10, 2011

Dinosaur Gum

Polio Vax Scene posted:

But what if I have a tumor on my dong, eh buddy? I'd like to see a key-value pair represent that

code:
[
    {
        "key": "butts",
        "value": "true"
    },
    {
        "key": "dongs",
        "value": [
            {
                "key": "value",
                "value": "false"
            },
            {
                "key": "hastumor",
                "value": "true"
            }
        ]
    }
]

repiv
Aug 13, 2009

https://twitter.com/rygorous/status/1049384200929914880

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
The Linux kernel loves to use inline-asm hacks for things that could've been very reasonable language features if they had any patience.

Magissima
Apr 15, 2013

I'd like to introduce you to some of the most special of our rocks and minerals.
Soiled Meat

Xik posted:

code:
[
    {
        "key": "butts",
        "value": "true"
    },
    {
        "key": "dongs",
        "value": [
            {
                "key": "value",
                "value": "false"
            },
            {
                "key": "hastumor",
                "value": "true"
            }
        ]
    }
]
Looking forward to writing a Dong class in Java with isHasTumor()

Absurd Alhazred
Mar 27, 2010

by Athanatos
https://twitter.com/isislovecruft/status/1049503354391552000

TheresaJayne
Jul 1, 2011
The one thing that makes me shudder is that there are language evangelists,

I know someone who is a kotlin geek, She tries to tell everyone that Java is Dead, Rails is Dead, Groovy is Dead you should all go to Kotlin you can do so much with one line.....

Yeah and you give up fine control when you shorten commands in that manner.

even in java it sucks - with Java 10

var temp = new ArrayList<Widget>();
var temp2 = new LinkedList<Widget>();
temp.AddAll(temp2); <--- compile error

Where as originally it would work because of this

List<Widget> temp = new ArrayList<>();
List<Widget> temp2 = new LinkedList<>();
temp.AddAll(temp2);

But each language has its arena for use, you wouldnt write a device driver in Kotlin you would use C/C++ or even assembler. Each language has its place or it wouldnt have been created. (except that religious language and operating system - that is idiotic) and those who scream to stop using the language you know and use something new because its new is wrong and they should be locked in a dark room watching php scroll by on a large monitor on the wall.

Xarn
Jun 26, 2015
That sure is an opinion.

Workaday Wizard
Oct 23, 2009

by Pragmatica

TheresaJayne posted:

The one thing that makes me shudder is that there are language evangelists,

I know someone who is a kotlin geek, She tries to tell everyone that Java is Dead, Rails is Dead, Groovy is Dead you should all go to Kotlin you can do so much with one line.....

Yeah and you give up fine control when you shorten commands in that manner.

even in java it sucks - with Java 10

var temp = new ArrayList<Widget>();
var temp2 = new LinkedList<Widget>();
temp.AddAll(temp2); <--- compile error

Where as originally it would work because of this

List<Widget> temp = new ArrayList<>();
List<Widget> temp2 = new LinkedList<>();
temp.AddAll(temp2);

But each language has its arena for use, you wouldnt write a device driver in Kotlin you would use C/C++ or even assembler. Each language has its place or it wouldnt have been created. (except that religious language and operating system - that is idiotic) and those who scream to stop using the language you know and use something new because its new is wrong and they should be locked in a dark room watching php scroll by on a large monitor on the wall.



You would have a point if you mentioned cost and risk. But technically Kotlin is both easier to write and maintain.

Also your example doesn’t work since you can specify variable types in Kotlin (e.g var x: MyType = MyTypeSubclass();).

Soricidus
Oct 21, 2010
freedom-hating statist shill

TheresaJayne posted:

even in java it sucks - with Java 10

var temp = new ArrayList<Widget>();
var temp2 = new LinkedList<Widget>();
temp.AddAll(temp2); <--- compile error

the compile error is because the method is called addAll, not AddAll

the code will work fine otherwise, because addAll on any Collection subtype will accept any other Collection subtype

TheresaJayne
Jul 1, 2011

Soricidus posted:

the compile error is because the method is called addAll, not AddAll

the code will work fine otherwise, because addAll on any Collection subtype will accept any other Collection subtype

under java 10 var will be auto cast to the right hand object meaning that the var contents would be ArrayList and LinkedList in turn- ok i typed from memory and got a case wrong - i have been doing a lot of .NET recently

ToxicFrog
Apr 26, 2008


TheresaJayne posted:

under java 10 var will be auto cast to the right hand object meaning that the var contents would be ArrayList and LinkedList in turn- ok i typed from memory and got a case wrong - i have been doing a lot of .NET recently

Both ArrayList<E> and LinkedList<E> pass typechecking against Collection<? extends E>, which is what addAll() takes.

Even if you explicitly specify the types as ArrayList and LinkedList it works:

code:
ArrayList temp = new ArrayList<Object>();
LinkedList temp2 = new LinkedList<Object>();
temp.addAll(temp2);

Slimy Hog
Apr 22, 2008

TheresaJayne posted:

except that religious language and operating system - that is idiotic

Tell me more

Illusive Fuck Man
Jul 5, 2004
RIP John McCain feel better xoxo 💋 ðŸ™Â
Taco Defender

Slimy Hog posted:

Tell me more

Probably talking about TempleOS / HolyC. Imo, that's not a horror because even the schizophrenic author doesn't expect anyone else to use / maintain it.

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.
Well, that's the least of his worries now.

Slimy Hog
Apr 22, 2008

Of course he was a goon:
https://forums.somethingawful.com/member.php?s=&action=getinfo&userid=177830

Taffer
Oct 15, 2010


TheresaJayne posted:

The one thing that makes me shudder is that there are language evangelists,

I know someone who is a kotlin geek, She tries to tell everyone that Java is Dead

Kotlin is amazing and Java is dead.

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.
No language is dead as long as enterprise exists.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Taffer posted:

Kotlin is amazing and Java is dead.

https://www.youtube.com/watch?v=yfelqZpapZA

Magissima
Apr 15, 2013

I'd like to introduce you to some of the most special of our rocks and minerals.
Soiled Meat

Taffer posted:

Kotlin is amazing and Java is dead.
What about for those of us not stuck in the Android ghetto?

CPColin
Sep 9, 2003

Big ol' smile.

SupSuper posted:

No language is dead as long as enterprise exists.

No language is dead as long as we remember it in our hearts

which is not how memory or hearts or dying works.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Magissima posted:

What about for those of us not stuck in the Android ghetto?

Kotlin was cool and good before Android adopted it!

Adbot
ADBOT LOVES YOU

Carbon dioxide
Oct 9, 2012

Kotlin is for those who want to get out of Java (a smart choice), keep using the jvm and useful java libraries (also a smart choice), but are too stuck in their ways to switch to superior Functional Programming entirely.

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