|
TheFreshmanWIT posted:I tend to stick to C++ these days, but I do a bunch of code reviews on it. This is the pattern that makes reviewing it most clearly: 1: It might be clear to you, but it's not necessarily clear to anyone else. The indications to me that that is meant to be a string are that it is called str and that 1 is added to the length; use of sizeof(char) doesn't tell me that at all since it could just as easily be an array of small signed integers. 2: I'll admit I was hoping that you would say code:
3: Again, my original point was that if you're going to use sizeof, there are very few reasons to use it on a type rather than a variable, and the real issue is that it seems too many people aren't aware that you can do this instead, which is strictly better in my opinion: code:
4: In C, you don't cast the result of calls to malloc
|
# ? Feb 15, 2015 17:28 |
|
|
# ? May 17, 2024 17:32 |
|
Steve French posted:1: It might be clear to you, but it's not necessarily clear to anyone else. The indications to me that that is meant to be a string are that it is called str and that 1 is added to the length; use of sizeof(char) doesn't tell me that at all since it could just as easily be an array of small signed integers. Admittedly I am not a C expert, bu this particular example seems really obtuse. Why would you initialize an array of type A by arbitrarily sizing it using the name of type B?
|
# ? Feb 15, 2015 17:36 |
|
LeftistMuslimObama posted:Admittedly I am not a C expert, bu this particular example seems really obtuse. Why would you initialize an array of type A by arbitrarily sizing it using the name of type B? Note that I said small signed integers, not small signed int. If you want a signed integer in the range [-127, 128], char is the primitive type for you. I'm not saying that the circumstances in which this makes sense are very common, just that it is a thing that is done, and is one example of a situation where char * is not meant to refer to a C string, but also isn't just a blob of bytes. Steve French fucked around with this message at 17:51 on Feb 15, 2015 |
# ? Feb 15, 2015 17:48 |
|
Karate Bastard posted:Any of you whippersnappers actually got to do this? In school, not as such, although I did have a few exams where you had to write code from scratch on the paper. I had to do a bunch of whiteboard coding for my last job interview, but it didn't have to be compiles-as-written correct.
|
# ? Feb 15, 2015 17:51 |
|
Steve French posted:If you want a signed integer in the range [-127, 128], char is the primitive type for you. If you want a signed integer, you should probably not pick a type that the standard explicitly allows to be unsigned if the compiler feels like it. It's 2015, use int8_t.
|
# ? Feb 15, 2015 18:02 |
|
Soricidus posted:If you want a signed integer, you should probably not pick a type that the standard explicitly allows to be unsigned if the compiler feels like it. A good point, and one that I'd forgotten about; this was perhaps not the best example. My intent was not to advocate for use of char that way, but I see that was basically what I wrote; I just meant to highlight that an array of char can be other things. My point still stands, which is that sizeof(char) does not indicate to me that the allocated memory is for use specifically as a null terminated C string vs some other array of char. Perhaps this is an established convention/idiom that I'm not aware of, but I still see no reason to write sizeof(char) rather than sizeof(*str)
|
# ? Feb 15, 2015 18:17 |
|
I agree with your main point btw.
|
# ? Feb 15, 2015 18:44 |
|
Steve French posted:Note that I said small signed integers, not small signed int. If you want a signed integer in the range [-127, 128], char is the primitive type for you. Specifically, signed char if that's what you mean. e;fb Subjunctive fucked around with this message at 18:57 on Feb 15, 2015 |
# ? Feb 15, 2015 18:44 |
|
TheFreshmanWIT posted:
|
# ? Feb 15, 2015 20:39 |
|
ToxicFrog posted:I had to do a bunch of whiteboard coding for my last job interview, but it didn't have to be compiles-as-written correct. If it has to be, the interviewers are doing it wrong.
|
# ? Feb 15, 2015 21:28 |
|
static typing is the root of all evil
|
# ? Feb 16, 2015 00:08 |
|
Why is it that the people who know least always shout loudest?
|
# ? Feb 16, 2015 00:18 |
|
Stupid people don't know enough to know they don't know anything.quote:Working with waterfall languages after working with agile languages is just painful. (Thanks to Andreas Ronge for coining the term Waterfall Language.)
|
# ? Feb 16, 2015 00:22 |
|
I like the part where he says "the reason the languages I like are more productive is because they're the languages I like."
|
# ? Feb 16, 2015 00:25 |
|
LeftistMuslimObama posted:I like the part where he says "the reason the languages I like are more productive is because they're the languages I like." That's the least wrong part of the whole screed.
|
# ? Feb 16, 2015 00:39 |
|
quote:Developing in Ruby feels much more elastic, kind of like using modeling clay to build something. You change it a bit, get immediate feedback, change it some more, and before you know it you’re done. With languages like Java, the modeling clay has a scaffolding around it that you need to move and alter before you’re allowed to touch the actual clay. So much of your day goes by tinkering with the scaffolding that you think it’s normal and necessary. Not discussed: whether this thing you've "modeled" is fit for any particular purpose other than looking good to you.
|
# ? Feb 16, 2015 00:50 |
|
Spatial posted:Stupid people don't know enough to know they don't know anything. When people say agile I lose a bit of faith in them, agile languages is a new and sad thing to me.
|
# ? Feb 16, 2015 00:54 |
|
I can't wait to live in a house made from clay. Unbaked clay. But at least none of that nasty restrictive scaffolding was required during construction!
|
# ? Feb 16, 2015 01:07 |
|
Soricidus posted:I can't wait to live in a house made from clay. Dynamically-typed interpreted languages are the synthetic modeling clay of the computer world. It will serve a function for a while, and then at some point it'll start to dissolve and lose its shape. It'll probably also give you cancer. ErIog fucked around with this message at 01:27 on Feb 16, 2015 |
# ? Feb 16, 2015 01:11 |
|
Soricidus posted:I can't wait to live in a house made from clay.
|
# ? Feb 16, 2015 01:19 |
|
quote:Aren’t all opinions made up out of thin air? An opinion is an opinion and even if others have a different experience, why should I change my opinion based on what other people think? quote:Or perhaps it’s more analogous to a bike with training wheels. They give you a sense of safety and comfort, but in reality they are what’s keeping you from going faster. Don’t be the kid who builds larger and fancier training wheels in order to go a little bit faster (would this be Scala in this analogy? , try losing the wheels for a while and see what happens. I don't think this commenter has ever ridden a bike.
|
# ? Feb 16, 2015 01:28 |
|
He's right, the less compiler oversight and static typing the better. That's why I only program in assembly. E: I actually thought that article was a joke when he called Smalltalk a "modern language". Didn't it come out the same year as C? Linear Zoetrope fucked around with this message at 04:15 on Feb 16, 2015 |
# ? Feb 16, 2015 04:07 |
|
SupSuper posted:
Probably not --- if he did, he probably would have ended up going top-speed, uncontrolled, down a hill, and then hit by cross traffic. Speed isn't the sole meaningful metric for bikes, either
|
# ? Feb 16, 2015 04:28 |
|
Pshh, dynamic typing is so last decade, it's all about duck typing now. For instance, here's a part of speech tagger from the Python NLTK library. It works like this:code:
code:
|
# ? Feb 16, 2015 04:39 |
|
When I was getting started on python, "%s thing" % (thing) always always caught me out.
|
# ? Feb 16, 2015 07:27 |
|
Bonfire Lit posted:adobe bricks aren't baked, and people build houses from them i am so tempted to say that i use my Apple Mini brick as a door stop.
|
# ? Feb 16, 2015 08:21 |
|
Bonfire Lit posted:adobe bricks aren't baked, and people build houses from them Well if you're going to get all pedantic then the sun-drying process is also analogous to compilation, and the inclusion of straw or manure represents
|
# ? Feb 16, 2015 11:05 |
|
Jsor posted:He's right, the less compiler oversight and static typing the better. That's why I only program in assembly. Smalltalk has continued to evolve, and the original design was far ahead of its time. It still feels quite "modern" in most ways, at least if you are comparing it to things like Ruby and Python. This does not make the original article less retared. He mentions that Haskell is his favorite language, but then admits that he never actually managed to write any code in it. Sounds like someone with serious static typing experience!
|
# ? Feb 16, 2015 12:54 |
|
qntm posted:
Why would you want to add 4? (Or 2, or 8. I'm sure there's somewhere where it's 1.) I mean, unless this is C++, in which case I have a lot of other questions.
|
# ? Feb 16, 2015 19:27 |
|
Are you seriously telling me that a character literal doesn't have type char?
|
# ? Feb 16, 2015 19:34 |
|
qntm posted:Are you seriously telling me that a character literal doesn't have type char? Character literals are promoted to ints in C. Try printf sizeof 'a'. Edit: see A6.1, page 197 in K&R. Double edit: vv My mistake, guess I misunderstood the material. Why is that, exactly? Fergus Mac Roich fucked around with this message at 19:44 on Feb 16, 2015 |
# ? Feb 16, 2015 19:37 |
|
They aren't promoted to ints, character constants are already ints.
|
# ? Feb 16, 2015 19:42 |
|
"Promotion" is just a word for a certain kind of implicit conversion. The basic C-family language rule is that you can look at any expression in isolation (from the rest of its statement, obviously not in isolation from its scope) and decide its type and its value kind (basically, l-value vs. r-value); using that expression in some specific context may then require an implicit conversion to some other type and value kind. Promotions are just those implicit conversions that increase the rank (roughly, widen) of integer or floating-point r-values. sizeof suppresses all conversions on its operand, so nothing is ever promoted there. C just makes everything that is even vaguely integer-constant-like int by default, basically because that's what it's always done and it's really too late to mess with it. Character literals are ints. Integer literals are ints unless they don't fit. Enumerators are ints even if they don't fit (but this is actually a point of widespread deviation). C++ makes better decisions about all of this, which is one of the reasons why C++ is a significantly better language than C even for primitive systems work (if you can convince yourself to only work with a subset of the language and standard library).
|
# ? Feb 16, 2015 20:57 |
|
I wish there was a variant of C that had all of C++'s modifications that make things sane again but with none of the junk added on top.
|
# ? Feb 16, 2015 22:26 |
|
This is less a coding horror and more of a security horror. A group (which seems likely to be U.S. government-affiliated) that had gone undetected for over a decade was discovered this past year, and it's been responsible for some serious poo poo. If you're curious about security, this story is pretty nuts. Here's a snippet: quote:GrayFish is the crowning achievement of the Equation Group. The malware platform is so complex that Kaspersky researchers still understand only a fraction of its capabilities and inner workings. Key to the sophistication of GrayFish is its bootkit, which allows it to take extraordinarily granular control of the machines it infects. Evil_Greven fucked around with this message at 22:53 on Feb 16, 2015 |
# ? Feb 16, 2015 22:50 |
|
Evil_Greven posted:This is less a coding horror and more of a security horror. quote:The stashing of malicious files in multiple branches of an infected computer's registry. By encrypting all malicious files and storing them in multiple branches of a computer's Windows registry, the infection was impossible to detect using antivirus software. I mean, I know nothing about this poo poo, but this sounds like gobbedly-gook from CSI. Multiple branches? Oh no we're hosed!
|
# ? Feb 16, 2015 22:54 |
|
Thermopyle posted:I mean, I know nothing about this poo poo, but this sounds like gobbedly-gook from CSI. Multiple branches? Oh no we're hosed! I read this as fragmenting the encrypted files in multiple locations (that happen to be registry keys) so that a scan looking for those files wouldn't find them in any one place.
|
# ? Feb 16, 2015 22:58 |
|
Thermopyle posted:I mean, I know nothing about this poo poo, but this sounds like gobbedly-gook from CSI. Multiple branches? Oh no we're hosed! AV is poo poo at detecting anything remotely advanced is the important take away from that sentence but Kaspersky doesn't want to sound incompetent.
|
# ? Feb 16, 2015 23:00 |
|
Suspicious Dish posted:I wish there was a variant of C that had all of C++'s modifications that make things sane again but with none of the junk added on top. It's really not that hard to just not use language features you don't want to use. The hard problem is getting two systems programmers to agree about what language features they don't want to use. If your goal is to be independent of the language runtime, turn off RTTI and exceptions and avoid most of the standard library. If your goal is to make binary-compatibility problems more obvious, either keep class types incomplete in your public interfaces or don't use virtual methods and special members there. If your goal is to enforce some unjustified bias against any feature that doesn't feel sufficiently C-like, do all of the above and also avoid member pointers and templates, even in your private interfaces and implementations.
|
# ? Feb 16, 2015 23:10 |
|
|
# ? May 17, 2024 17:32 |
|
rjmccall posted:If your goal is to be independent of the language runtime, turn off RTTI and exceptions and avoid most of the standard library. Sadly, this will still require you to link against libstdc++, which is just a time bomb waiting for the standard committee or gcc to break unrelated C++ libraries in your application.
|
# ? Feb 16, 2015 23:24 |