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
brap
Aug 23, 2004

Grimey Drawer
It's a moot point in c# because autoproperties are as easy as a field.
In java you have to declare a field and two boilerplate methods every time. It's crappy.

Adbot
ADBOT LOVES YOU

ullerrm
Dec 31, 2012

Oh, the network slogan is true -- "watch FOX and be damned for all eternity!"

No, that's likely C++ you're thinking of. In C++, structs and classes are identical except for their default member visibility; its convention that structs are used for "plain old data" while classes are used for things that have deeper behavior or that represent hardware.

In C# structs are a weird thing largely intended for performance critical code or interop with unmanaged code -- they're similar to classes but are always allocated on the stack or passed by value. They can have some unintuitive lifetimes and are best used with care.

NihilCredo
Jun 6, 2011

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

.NET structures are meant for very small dumb data holders or thin wrappers, small enough that it's cheaper to copy them everywhere than to pass a reference. I believe the max recommended size is 16 bytes iirc.

Karate Bastard
Jul 31, 2007

Soiled Meat
code:
tokens = [
    '8ottifukItOij/',
    '5Twewv#odNiedUn',
    'Kintemlic,of0'
    'dekBabr6Otjiv`',
    '7olooncamAcdym_',
    'neilvyur8omFat\\',
    ]

print tokens
Actual data removed to protect my rear end.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Karate Bastard posted:

code:
tokens = [
    '8ottifukItOij/',
    '5Twewv#odNiedUn',
    'Kintemlic,of0'
    'dekBabr6Otjiv`',
    '7olooncamAcdym_',
    'neilvyur8omFat\\',
    ]

print tokens
Actual data removed to protect my rear end.

It took me a while to see what was wrong with this. It raises a good point re: whether being able to write "string1" "string2" and have it mean "string1string2" is always a good thing (even though it can be convenient - but you can always just type a +). Are there any static analysis tools that would have picked this up?

Soricidus
Oct 21, 2010
freedom-hating statist shill

fleshweasel posted:

It's a moot point in c# because autoproperties are as easy as a field.
In java you have to declare a field and two boilerplate methods every time. It's crappy.

Just use lombok if it bothers you?

Karate Bastard
Jul 31, 2007

Soiled Meat

Hammerite posted:

It took me a while to see what was wrong with this. It raises a good point re: whether being able to write "string1" "string2" and have it mean "string1string2" is always a good thing (even though it can be convenient - but you can always just type a +). Are there any static analysis tools that would have picked this up?

I don't know?

This is the fist time I've been bitten by this (HOW DO I KNOW? you ask, and the answer is ????). It's perfectly legal python. A saving grace is that this probably leads to more obvious errors down the line (off-by-one, key errors...), and typically you only do this for small lists so the risk is proportionally smaller, but you can't really be sure.

There's of course also this variation of the same that can bite you just as easily

code:
def tokenator(a, b, c, *tokens):
	print c
	print tokens

tokenator('8ottifukItOij/', '5Twewv#odNiedUn', 'Kintemlic,of0'  'dekBabr6Otjiv`', '7olooncamAcdym_')
And now I'm giggling at '8ott i fuk it Oi j/' which is a genuine nonce generated by my compy as valuable contribution to this discussion.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

ullerrm posted:

classes are used for things that have deeper behavior or that represent hardware.

I've never heard the hardware part before, can you elaborate?

ToxicFrog
Apr 26, 2008


Hammerite posted:

It took me a while to see what was wrong with this. It raises a good point re: whether being able to write "string1" "string2" and have it mean "string1string2" is always a good thing (even though it can be convenient - but you can always just type a +). Are there any static analysis tools that would have picked this up?

Pylint will catch that at work, but I know we have a bunch of custom rules for it, so I don't know if that's part of pylint out of the box.

canis minor
May 4, 2011

Defining phone numbers as signed integers. (in XSD)

Which appears to be invalidated either way by the server. (because it lacks +)

In an endpoint for API of UK post service provider.

canis minor fucked around with this message at 15:00 on Oct 13, 2015

Meat Beat Agent
Aug 5, 2007

felonious assault with a sproinging boner
Well if phone numbers aren't supposed to be signed ints then how come they start with plus signs all the time?

sarehu
Apr 20, 2007

(call/cc call/cc)
At least that would prevent the bug where we thought two different people were actually the same person because two different address book entries used "same" in an Outlook addressbook field.

feedmegin
Jul 30, 2008

Subjunctive posted:

I've never heard the hardware part before, can you elaborate?

Me either. If I see something like that 'representing hardware' it's usually a struct because it's full of unsigned ints that are directly mapped to registers on said hardware and you don't want hidden vtbl pointers and whatever messing all that up. :shobon:

Kazinsal
Dec 13, 2011
It's nice to be able to instantiate a new object of a class for a certain piece of hardware if there happen to be multiple of that hardware in the system. Find two RTL8169s on the PCI bus? Spin up two NetRealtek8169s or whatever.

Of course, you can approximate that with structs and function pointers in C if you're working in C, but C++ throws in poo poo like inheritance, which would be useful for similar chips that have slightly different register layouts and all that.

Space Kablooey
May 6, 2009


Karate Bastard posted:

code:
tokens = [
    '8ottifukItOij/',
    '5Twewv#odNiedUn',
    'Kintemlic,of0'
    'dekBabr6Otjiv`',
    '7olooncamAcdym_',
    'neilvyur8omFat\\',
    ]

print tokens
Actual data removed to protect my rear end.

That bit me once when it was a list of document categories, and two categories weren't being registered properly, and why are these two categories concatenated and then someone else pointed out to me and then I :(.

How's this useful in any way?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
It's required for building strings in the C preprocessor because you can't do "a" + "b". It is not useful in any other languages but everyone loves to cargo-cult C things that don't actually make sense for their non-C language.

feedmegin
Jul 30, 2008

Plorkyeran posted:

It's required for building strings in the C preprocessor because you can't do "a" + "b". It is not useful in any other languages but everyone loves to cargo-cult C things that don't actually make sense for their non-C language.

It's also nice if you need a reaaaaaally long string constant for some reason and you want it on multiple lines rather than having a 5,000,000 character wide line in your text editor.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

feedmegin posted:

It's also nice if you need a reaaaaaally long string constant for some reason and you want it on multiple lines rather than having a 5,000,000 character wide line in your text editor.

That's handy in C, but not actually relevant for any of the derivative languages that also have an actual string concatenation operator.

No Safe Word
Feb 26, 2005

Jabor posted:

That's handy in C, but not actually relevant for any of the derivative languages that also have an actual string concatenation operator.

Or native multiline string support.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

You don't always want to incur runtime overhead for concatenation, and not all interpreters will statically optimize that pattern to be a string constant.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Rather than adding a language feature just to work around lovely interpreters you could just require that they do the right thing.

Karate Bastard
Jul 31, 2007

Soiled Meat

Subjunctive posted:

You don't always want to incur runtime overhead for concatenation, and not all interpreters will statically optimize that pattern to be a string constant.

Well don't repeatedly recreate it then?

lord of the files
Sep 4, 2012

code:
tokens = [
    '8ottifukItOij/',
    '5Twewv#odNiedUn',
    'Kintemlic,of0'
    'dekBabr6Otjiv`',
    '7olooncamAcdym_',
    'neilvyur8omFat\\',
    ]

print tokens
the only thing i can see this being useful for is string concatenation for larger strings. at the same time it can be confusing when you miss that comma and you get off-by-one errors of missing strings in your case. most IDEs have built in multi-line string support, if you are using a multi-line string big enough that you are using this concatenation method, why would you not just have the IDE fix the formatting for you?

feedmegin
Jul 30, 2008

Jabor posted:

That's handy in C, but not actually relevant for any of the derivative languages that also have an actual string concatenation operator.

Also handy in C++, which does have a (std:: )string concatenation operator but where string constants aren't actually std::strings :sun:

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Karate Bastard posted:

code:
tokens = [
    '8ottifukItOij/',
    '5Twewv#odNiedUn',
    'Kintemlic,of0'
    'dekBabr6Otjiv`',
    '7olooncamAcdym_',
    'neilvyur8omFat\\',
    ]

print tokens
Actual data removed to protect my rear end.

huh I had no idea this was a thing. I thought this only worked between parenthesis, like something like this:

Python code:
tokens = [
    '8ottifukItOij/',
    '5Twewv#odNiedUn',
    ('Kintemlic,of0'
     'dekBabr6Otjiv`'),
    '7olooncamAcdym_',
    'neilvyur8omFat\\',
    ]

print tokens
...but not in the way you did it. I mean you can't do this:

Python code:
butt = 'fffff'
       'art'
sigh

GUIIIIIIIDOOOOOOOOOOOO :argh:

Symbolic Butt fucked around with this message at 21:27 on Oct 13, 2015

Xarn
Jun 26, 2015

feedmegin posted:

Also handy in C++, which does have a (std:: )string concatenation operator but where string constants aren't actually std::strings :sun:

code:
std::cout << "hello"s + " world\n";

>>> hello world
:2bong:

Volte
Oct 4, 2004

woosh woosh

Symbolic Butt posted:

huh I had no idea this was a thing. I thought this only worked between parenthesis, like something like this:

Python code:
tokens = [
    '8ottifukItOij/',
    '5Twewv#odNiedUn',
    ('Kintemlic,of0'
     'dekBabr6Otjiv`'),
    '7olooncamAcdym_',
    'neilvyur8omFat\\',
    ]

print tokens
...but not in the way you did it. I mean you can't do this:

Python code:
I mean you can't do this:

butt = 'fffff'
       'art'
sigh

GUIIIIIIIDOOOOOOOOOOOO :argh:
It's between square brackets, which has the same effect.

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

Xarn posted:

code:
std::cout << "hello"s + " world\n";

>>> hello world
:2bong:

code:
#include <stdio.h>

int main (void) {
    printf("%s\n", "hello " "there :)");
    return 0;
}

>>> hello there :)
http://codepad.org/k7PNQuak

Space Kablooey
May 6, 2009


Symbolic Butt posted:

Python code:
butt = 'fffff'
       'art'
sigh

GUIIIIIIIDOOOOOOOOOOOO :argh:

You can do it if you add the \ between them, which is the same thing as putting in the same line.
Python code:
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 'fffff' 'art'
'fffffart'
>>> 'fffff' \
... 'art'
'fffffart'

pseudorandom name
May 6, 2007

feedmegin posted:

Also handy in C++, which does have a (std:: )string concatenation operator but where string constants aren't actually std::strings :sun:

And std::strings cannot be constants.



Oh, and that classes representing hardware thing probably means that they're proxies for actual hardware and the accessor methods poke the device instead of member variables.

feedmegin
Jul 30, 2008

Xarn posted:

code:
std::cout << "hello"s + " world\n";

>>> hello world
:2bong:

Ooh, neato. Be a while before most of us can rely on having C++14 available sadly :)

Xarn
Jun 26, 2015

feedmegin posted:

Ooh, neato. Be a while before most of us can rely on having C++14 available sadly :)

Yeah, my work is at C++03 in name of portability...

The funny thing is, we compile with VSC++, which doesn't have strict mode, and with Clang set to C++11 :v:
Luckily no-one will ever ask us to support C++03, so I won't have to fix all this poo poo.

Zopotantor
Feb 24, 2013

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

Xarn posted:

Yeah, my work is at C++03 in name of portability...

For me it's backwards compatibility. So far RedHat refuses to guarantee that the C++11 ABI in RHEL 7 will remain stable. :argh:

Mogomra
Nov 5, 2005

simply having a wonderful time
Not the most horrifying thing I've ever seen, but certainly :pwn:

code:
for (var i = 0; i < 26; i++) {
	if (typeof request.app.requestData.fields['image_' + i + '_websrc'] !== 'undefined') {
		if (request.app.requestData.fields['image_' + i + '_websrc'].length > 0) {
			fileCountToGrab++;
			var VALID_EXTS = [".jpg", ".jpeg", ".bmp", ".png", ".gif", "ttf", "otf"];
			if (VALID_EXTS.indexOf(request.app.requestData.fields['image_' + i + '_websrc'].toLowerCase().substring(request.app.requestData.fields['image_' + i + '_websrc'].toLowerCase().length - 4).toLowerCase()) == -1 && VALID_EXTS.indexOf(request.app.requestData.fields['image_' + i + '_websrc'].toLowerCase().substring(request.app.requestData.fields['image_' + i + '_websrc'].toLowerCase().length - 5).toLowerCase()) == -1) {
				return false;
			}
		}
	}
}

Pavlov
Oct 21, 2012

I've long been fascinated with how the alt-right develops elaborate and obscure dog whistles to try to communicate their meaning without having to say it out loud
Stepan Andreyevich Bandera being the most prominent example of that
well as an 80 char per line pureist

Soricidus
Oct 21, 2010
freedom-hating statist shill

Mogomra posted:

Not the most horrifying thing I've ever seen, but certainly :pwn:

code:
for (var i = 0; i < 26; i++) {
	if (typeof request.app.requestData.fields['image_' + i + '_websrc'] !== 'undefined') {
		if (request.app.requestData.fields['image_' + i + '_websrc'].length > 0) {
			fileCountToGrab++;
			var VALID_EXTS = [".jpg", ".jpeg", ".bmp", ".png", ".gif", "ttf", "otf"];
			if (VALID_EXTS.indexOf(request.app.requestData.fields['image_' + i + '_websrc'].toLowerCase().substring(request.app.requestData.fields['image_' + i + '_websrc'].toLowerCase().length - 4).toLowerCase()) == -1 && VALID_EXTS.indexOf(request.app.requestData.fields['image_' + i + '_websrc'].toLowerCase().substring(request.app.requestData.fields['image_' + i + '_websrc'].toLowerCase().length - 5).toLowerCase()) == -1) {
				return false;
			}
		}
	}
}

some people, when confronted with a problem, think "i know, i won't use regular expressions. or variables."

Karate Bastard
Jul 31, 2007

Soiled Meat
At least they used if.

qntm
Jun 17, 2009

Mogomra posted:

Not the most horrifying thing I've ever seen, but certainly :pwn:

code:
for (var i = 0; i < 26; i++) {
	if (typeof request.app.requestData.fields['image_' + i + '_websrc'] !== 'undefined') {
		if (request.app.requestData.fields['image_' + i + '_websrc'].length > 0) {
			fileCountToGrab++;
			var VALID_EXTS = [".jpg", ".jpeg", ".bmp", ".png", ".gif", "ttf", "otf"];
			if (VALID_EXTS.indexOf(request.app.requestData.fields['image_' + i + '_websrc'].toLowerCase().substring(request.app.requestData.fields['image_' + i + '_websrc'].toLowerCase().length - 4).toLowerCase()) == -1 && VALID_EXTS.indexOf(request.app.requestData.fields['image_' + i + '_websrc'].toLowerCase().substring(request.app.requestData.fields['image_' + i + '_websrc'].toLowerCase().length - 5).toLowerCase()) == -1) {
				return false;
			}
		}
	}
}

I'm going to go with .toLowerCase().length as my personal highlight here.

xzzy
Mar 5, 2009

Soricidus posted:

some people, when confronted with a problem, think "i know, i won't use regular expressions. or variables."

They probably have a plaque on the wall quoting JWZ's opinion of regex.

Adbot
ADBOT LOVES YOU

lord of the files
Sep 4, 2012

and only one gold star goes for the if statement. at least he didn't use a ternary operator.

lord of the files fucked around with this message at 19:53 on Oct 15, 2015

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