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
redleader
Aug 18, 2005

Engage according to operational parameters
unnecessarily, dangerously clever code, according to rob pike:

code:

List<string> things = new List<string>();

Adbot
ADBOT LOVES YOU

Carbon dioxide
Oct 9, 2012

redleader posted:

unnecessarily, dangerously clever code, according to rob pike:

code:
List<string> things = new List<string>();

According to the code block that's C#. I don't know C# well but this looks like valid Java too - if it was it would be a coding horror though.
In Java, the String type has a capital S. This could would imply that someone made a custom string class starting with a lowercase which is all kinds of wrong and confusing.

SirViver
Oct 22, 2008

Carbon dioxide posted:

According to the code block that's C#. I don't know C# well but this looks like valid Java too - if it was it would be a coding horror though.
In Java, the String type has a capital S. This could would imply that someone made a custom string class starting with a lowercase which is all kinds of wrong and confusing.
In C# "string" is the built-in alias for "System.String", just like "int" is for "System.Int32". You can use the alias/type interchangeably, though there's no reason to use anything but the alias.

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.
If it was Java they'd be instantiating an ArrayList instead of a List though.

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man
Is there type inference in java or c# or is using their equivalent of auto too advanced

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.
Both languages have the 'var' keyword, yes.

Space Gopher
Jul 31, 2006

BLITHERING IDIOT AND HARDCORE DURIAN APOLOGIST. LET ME TELL YOU WHY THIS SHIT DON'T STINK EVEN THOUGH WE ALL KNOW IT DOES BECAUSE I'M SUPER CULTURED.

Carbon dioxide posted:

According to the code block that's C#. I don't know C# well but this looks like valid Java too - if it was it would be a coding horror though.
In Java, the String type has a capital S. This could would imply that someone made a custom string class starting with a lowercase which is all kinds of wrong and confusing.

Go actually supports built-in dynamic arrays called "slices" that behave kind of like C# Lists and Java ArrayLists (with a few additional tricks against backing arrays) and are used in the same kind of problems.

But, more generally, Go hates constructors and wants to work with structs rather than objects. A new struct is given to you zeroed out - which wouldn't work for a like-for-like implementation of a Java ArrayList, because it has to instantiate the backing array and store a nonzero size. Instead, in Go, you need to make factory methods, and treat the "new" operator as an implementation detail in that factory method.

Go takes a lot of ideas from object oriented languages, but it tries to sell itself as "post object oriented" - so, coming from Java, C#, or even C++, you end up with a lot of "what the hell, why won't it do that?" moments.

OddObserver
Apr 3, 2009
Making it harder to enforce object invariants seems like something that belongs in this thread, yes.

redleader
Aug 18, 2005

Engage according to operational parameters

Carbon dioxide posted:

According to the code block that's C#. I don't know C# well but this looks like valid Java too - if it was it would be a coding horror though.
In Java, the String type has a capital S. This could would imply that someone made a custom string class starting with a lowercase which is all kinds of wrong and confusing.

the joke is go hates generics

redleader
Aug 18, 2005

Engage according to operational parameters
more generally, the joke is go itself

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


ironically, the more i have learned Rust and Haskell, the more i have moderated my scorn of Go; there's something to be said for obsessively prioritizing compilation speed at the cost of even obviously sensible language constructs.

DearSirXNORMadam
Aug 1, 2009

Doc Hawkins posted:

ironically, the more i have learned Rust and Haskell, the more i have moderated my scorn of Go; there's something to be said for obsessively prioritizing compilation speed at the cost of even obviously sensible language constructs.

I've often heard complaints about Rust's compilation speed, but I never really got them. Is there a particular type of code that compiles especially slowly or something? I've rarely had a project take more than 10-20 seconds to compile in Rust after it finishes downloading/and compiling the included stuff the first time. Normally if I'm iterating compilations for a project I am working on it hardly ever takes substantial time, and I've written like 10k+ line programs. (Admittedly my code is usually fairly simplistic math stuff)

necrotic
Aug 2, 2005
I owe my brother big time for this!
IIRC slowness tends to come from complicated types and macro usage. If you're doing mostly math it'll compile pretty quick.

It's also definitely gotten better over time.

DearSirXNORMadam
Aug 1, 2009

necrotic posted:

IIRC slowness tends to come from complicated types and macro usage. If you're doing mostly math it'll compile pretty quick.

It's also definitely gotten better over time.

I only ever got as far as Data Structures in CS (all that my major called for), so I was never clear on this, what's the use case for macros vs other ways of achieving similar goals? The most common use case for macros I've seen in Rust is a variable number of arguments (eg for println! or format!), but if you really want such a thing I can imagine passing a vec of trait objects to a function that ensures everything has a .tostr() method.

The other one that people often mention is generating actual code procedurally, which I've seen most commonly implemented for writing a scary version of generic code (for example generating typed functions that serve as wrappers for BLAS in order to hook up to a Fortran linked library). When I was looking at that library I was REALLY unclear on why they didn't go with a generic version of the code using some trait instead, since at compile time it should all boil down to the same thing.

For me the platonic ideal of a situation where recursion leads to clean code that makes total sense is divide-and-conquer searching, and the platonic ideal of a situation where object-oriented code leads to clean code that makes total sense is linked lists (leaving aside the fact that linked lists are a bad idea 99% of the time)

What's the platonic ideal of a situation where a macro leads to really clean code, but if you tried to do it with normal code you would get a giant mess?

DearSirXNORMadam fucked around with this message at 01:43 on Oct 24, 2020

1337JiveTurkey
Feb 17, 2005

Scala macros have been used to translate language constructs into typesafe representations of those constructs in other languages at compile time. One example is Slick, which turns Scala expressions into equivalent SQL code. There's also another for OpenCL that I can't remember off the top of my head which turns Scala expressions into shaders that can run on the GPU.

Having SQL or GLSL embedded in with the rest of your codebase isn't that messy but it's nice to just have a plain old for loop that you pass to a special executor and poof it's running on your GPU without having to switch to glorified C.

Carbon dioxide
Oct 9, 2012

1337JiveTurkey posted:

Scala macros have been used to translate language constructs into typesafe representations of those constructs in other languages at compile time. One example is Slick, which turns Scala expressions into equivalent SQL code. There's also another for OpenCL that I can't remember off the top of my head which turns Scala expressions into shaders that can run on the GPU.

Having SQL or GLSL embedded in with the rest of your codebase isn't that messy but it's nice to just have a plain old for loop that you pass to a special executor and poof it's running on your GPU without having to switch to glorified C.

Having experience with Slick, it works but I find it a bit annoying to use. If you need more complicated queries you need to struggle quite a bit to get it to do what you want. And things can also get annoying once you want to make use of stuff that's not db engine agnostic.

fritz
Jul 26, 2003

Soricidus posted:

Ok, have fun going to the dentist who uses iron tongs and a sharp scraping stick, I’ll stick with professionals using modern sophisticated tools that might be dangerous in untrained hands but allow a skilled practitioner to do a better job.

The dentist has gone thru a standardized training regimen and is licensed by the state.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

fritz posted:

The dentist has gone thru a standardized training regimen and is licensed by the state.

The more relevant difference, IMO, is that a dentist is very easy to hold accountable for any damage they cause.

Lawyers are formally trained and licensed too, but they're quite capable of getting away with incompetence.

xtal
Jan 9, 2011

by Fluffdaddy

fritz posted:

The dentist has gone thru a standardized training regimen and is licensed by the state.

Medical malpractice is a leading cause of death, not really a great example if you're trying to make credentialism sound like a good thing

Athas
Aug 6, 2007

fuck that joker

xtal posted:

Medical malpractice is a leading cause of death, not really a great example if you're trying to make credentialism sound like a good thing

Yeah, the death rate for hospital patients is also way higher than for the population in general. Stay home and write code instead!

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


xtal posted:

Medical malpractice is a leading cause of death, not really a great example if you're trying to make credentialism sound like a good thing

Medical errors matter, but the studies that people cite for them being the third leading cause of death are pretty questionable.

Ola
Jul 19, 2004

Coding malpractice:

https://twitter.com/sandofsky/status/1321593104298725376

QuarkJets
Sep 8, 2008

tickets and coins :chanpop:

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Why would you want to let your currency work for both cosmetics AND cheating? Jeez.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


https://twitter.com/q3k/status/1322943395497680897

Votlook
Aug 20, 2005

OMG, this is a horror on so many levels

Zorro KingOfEngland
May 7, 2008

wikipedia posted:

Zhejiang Dahua Technology Co., Ltd. is a partially state-owned Chinese company which sells video surveillance products and services

Wow. That's... terrifying.

CPColin
Sep 9, 2003

Big ol' smile.
Working on updating a little web application that helps HR enter information when setting up a new employee. Nodding my head in approval at the hoops the code jumps through when it comes to things like SSN, where that column is encrypted in the web application's database; it's not re-populated in the form after the employee has been saved; and so on.

The function that saves the form to the database dumps all the POSTed parameters into the application log, in plain text.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Well how else would you debug it?

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


code:
#include <Rcpp.h>

#include <string>
#include <vector>

using namespace Rcpp;

// [[Rcpp::plugins("cpp11")]]

// [[Rcpp::export]]
List f()
{
    std::vector<int>         v1 = {1, 2, 3, 4};
    std::vector<std::string> v2 = {"a", "b", "c"};
    std::vector<double>      v3 = {5.0, 6.0, 7.8, 9, 123};
    
    return List::create(Named("name1") = v1, Named("name2") = v2, Named("name3") = v3);
}

more falafel please
Feb 26, 2005

forums poster

ultrafilter posted:

code:
#include <Rcpp.h>

#include <string>
#include <vector>

using namespace Rcpp;

// [[Rcpp::plugins("cpp11")]]

// [[Rcpp::export]]
List f()
{
    std::vector<int>         v1 = {1, 2, 3, 4};
    std::vector<std::string> v2 = {"a", "b", "c"};
    std::vector<double>      v3 = {5.0, 6.0, 7.8, 9, 123};
    
    return List::create(Named("name1") = v1, Named("name2") = v2, Named("name3") = v3);
}

this seems fine once i googled what rcpp was?

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


C++ doesn't have named arguments. My code isn't the horror.

SurgicalOntologist
Jun 17, 2004

gently caress, we use Dahua cameras.

Tei
Feb 19, 2011

Database calculating accumulated of column - Quantities are euros

User report the accumulated total is wrong in some report by 4 euros
We check it

1) Column is float in the database (mysql)- Changing it to decimal(13 2) fix the 4 euros- but the total is still of by 21 cents- I guess float not good for money
2) The accumulated total is calculated with a session variable defined has @total:=0 ---- the fix is to change that to @total:=0.00 so it inherit a floating type instead of a integer?

Jeb Bush 2012
Apr 4, 2007

A mathematician, like a painter or poet, is a maker of patterns. If his patterns are more permanent than theirs, it is because they are made with ideas.
https://amp.theguardian.com/uk-news/2020/nov/06/companies-house-forces-business-name-change-to-prevent-security-risk

quote:

The company now legally known as “THAT COMPANY WHOSE NAME USED TO CONTAIN HTML SCRIPT TAGS LTD” was set up by a British software engineer, who says he did it purely because he thought it would be “a fun playful name” for his consulting business.

He now says he didn’t realise that Companies House was actually vulnerable to the extremely simple technique he used, known as “cross-site scripting”, which allows an attacker to run code from one website on another.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

It's unclear if there was actually a vulnerability triggered, or if they were just being cautious.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


anything which can be destroyed by crafted input should be

Zopotantor
Feb 24, 2013

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

Doc Hawkins posted:

anything which can be destroyed by crafted input should be

mods, please change my username to '); DROP TABLE Goons; —

Jazerus
May 24, 2011


i wonder how many countries you could evade taxes in if you were NULL, LLC

Adbot
ADBOT LOVES YOU

The Fool
Oct 16, 2003


Jazerus posted:

i wonder how many countries you could evade taxes in if you were NULL, LLC

you'll just get all the extra taxes they couldn't figure out for other people

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