|
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.
|
# ? Oct 13, 2015 06:41 |
|
|
# ? May 27, 2024 04:01 |
|
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.
|
# ? Oct 13, 2015 07:24 |
|
.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.
|
# ? Oct 13, 2015 08:02 |
|
code:
|
# ? Oct 13, 2015 08:25 |
|
Karate Bastard 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?
|
# ? Oct 13, 2015 09:27 |
|
fleshweasel posted:It's a moot point in c# because autoproperties are as easy as a field. Just use lombok if it bothers you?
|
# ? Oct 13, 2015 10:05 |
|
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:
|
# ? Oct 13, 2015 10:30 |
|
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?
|
# ? Oct 13, 2015 10:55 |
|
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.
|
# ? Oct 13, 2015 13:03 |
|
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 |
# ? Oct 13, 2015 13:49 |
|
Well if phone numbers aren't supposed to be signed ints then how come they start with plus signs all the time?
|
# ? Oct 13, 2015 14:47 |
|
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.
|
# ? Oct 13, 2015 15:04 |
|
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.
|
# ? Oct 13, 2015 15:19 |
|
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.
|
# ? Oct 13, 2015 15:37 |
|
Karate Bastard posted:
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?
|
# ? Oct 13, 2015 16:06 |
|
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.
|
# ? Oct 13, 2015 16:20 |
|
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.
|
# ? Oct 13, 2015 16:26 |
|
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.
|
# ? Oct 13, 2015 16:30 |
|
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.
|
# ? Oct 13, 2015 16:32 |
|
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.
|
# ? Oct 13, 2015 16:48 |
|
Rather than adding a language feature just to work around lovely interpreters you could just require that they do the right thing.
|
# ? Oct 13, 2015 17:03 |
|
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?
|
# ? Oct 13, 2015 17:04 |
|
code:
|
# ? Oct 13, 2015 17:12 |
|
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
|
# ? Oct 13, 2015 17:15 |
|
Karate Bastard posted:
huh I had no idea this was a thing. I thought this only worked between parenthesis, like something like this: Python code:
Python code:
GUIIIIIIIDOOOOOOOOOOOO Symbolic Butt fucked around with this message at 21:27 on Oct 13, 2015 |
# ? Oct 13, 2015 20:59 |
|
feedmegin posted:Also handy in C++, which does have a (std:: )string concatenation operator but where string constants aren't actually std::strings code:
|
# ? Oct 13, 2015 21:26 |
|
Symbolic Butt posted:huh I had no idea this was a thing. I thought this only worked between parenthesis, like something like this:
|
# ? Oct 13, 2015 21:27 |
|
Xarn posted:
code:
|
# ? Oct 13, 2015 21:35 |
|
Symbolic Butt posted:
You can do it if you add the \ between them, which is the same thing as putting in the same line. Python code:
|
# ? Oct 13, 2015 21:41 |
|
feedmegin posted:Also handy in C++, which does have a (std:: )string concatenation operator but where string constants aren't actually std::strings 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.
|
# ? Oct 13, 2015 21:47 |
|
Xarn posted:
Ooh, neato. Be a while before most of us can rely on having C++14 available sadly
|
# ? Oct 14, 2015 11:25 |
|
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 Luckily no-one will ever ask us to support C++03, so I won't have to fix all this poo poo.
|
# ? Oct 14, 2015 13:59 |
|
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.
|
# ? Oct 14, 2015 16:29 |
|
Not the most horrifying thing I've ever seen, but certainly code:
|
# ? Oct 15, 2015 18:56 |
|
well as an 80 char per line pureist
|
# ? Oct 15, 2015 18:57 |
|
Mogomra posted:Not the most horrifying thing I've ever seen, but certainly some people, when confronted with a problem, think "i know, i won't use regular expressions. or variables."
|
# ? Oct 15, 2015 19:03 |
|
At least they used if.
|
# ? Oct 15, 2015 19:09 |
|
Mogomra posted:Not the most horrifying thing I've ever seen, but certainly I'm going to go with .toLowerCase().length as my personal highlight here.
|
# ? Oct 15, 2015 19:36 |
|
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.
|
# ? Oct 15, 2015 19:37 |
|
|
# ? May 27, 2024 04:01 |
|
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 |
# ? Oct 15, 2015 19:51 |