|
ctz posted:
Yeah, unfortunately, I was posting from my iPad so google and a terminal were too complicated to actually test anything out. But I recall that languages that do this type of comparison usually have a 'strict' comparison to go along with it, and I thought python was one of them
|
# ? Sep 27, 2010 10:40 |
|
|
# ? May 25, 2024 13:39 |
|
http://search.cpan.org/~dsugal/Taint-0.07/Taint.pm Perl does it differently, what with it being a dynamic language. Seriously people, this is babbies first programming argument in here.
|
# ? Sep 27, 2010 11:15 |
|
I've never been responsible for employee interviews before, but if I ever am, I'm asking a question about how the candidate feels about type coercions.
|
# ? Sep 27, 2010 13:28 |
|
king_kilr posted:I've never been responsible for employee interviews before, but if I ever am, I'm asking a question about how the candidate feels about type coercions. are you going to ask that in order to see whether they agree with you, or to see what knowledge they display about the subject and what reasoning they give for their opinion?
|
# ? Sep 27, 2010 13:30 |
|
Hammerite posted:are you going to ask that in order to see whether they agree with you, or to see what knowledge they display about the subject and what reasoning they give for their opinion? Both.
|
# ? Sep 27, 2010 13:41 |
|
code:
|
# ? Sep 27, 2010 14:44 |
|
Lysandus posted:
I think this could be defensible, depending on what exactly it's being used to do. Similar to how while (true) {...} can be a useful control structure.
|
# ? Sep 27, 2010 15:00 |
|
Have you heard of the if statement?
|
# ? Sep 27, 2010 15:12 |
|
Mustach posted:Have you heard of the if statement? Yes, I have. I sense that you think you are making a point in a pithy fashion. Please make your point more explicitly.
|
# ? Sep 27, 2010 17:46 |
|
Lysandus posted:
This could be pretty powerful if merged with the FOR-CASE idiom.
|
# ? Sep 27, 2010 17:54 |
|
Hammerite posted:I think this could be defensible, depending on what exactly it's being used to do. Similar to how while (true) {...} can be a useful control structure. It does things exactly once. Unless you are doing i--; in the body, which is just all kinds of hosed up. The for statement might as well not exist. while(true) is a completely different control structure and actually has a use.
|
# ? Sep 27, 2010 18:10 |
|
Hammerite posted:I think this could be defensible, depending on what exactly it's being used to do. Similar to how while (true) {...} can be a useful control structure. You might've had a point with do { .. } while(0), but you missed your chance.
|
# ? Sep 27, 2010 18:18 |
|
Ryouga Inverse posted:It does things exactly once. Unless you are doing i--; in the body... Yes, I realise that. Ryouga Inverse posted:... which is just all kinds of hosed up. It wouldn't appear likely to be the best way of achieving whatever is intended, but I don't think it's clear-cut enough to write off as definitely wrong in all situations. Chances are high (given the thread) that in the code it was taken from it was not appropriate, but I cannot conclude that any and every use of it would be indefensible. Ryouga Inverse posted:while(true) is a completely different control structure and actually has a use. Different in effect, certainly. I'm not sure it qualifies as being different in style. Both are ways of using looping structures that aren't on the face of it the "usual" or most straightforward way of using those structures.
|
# ? Sep 27, 2010 18:21 |
|
pokeyman posted:You might've had a point with do { .. } while(0), but you missed your chance. I don't see what you mean. Yes, do { ... } while (false) is another good example, although as far as I am aware it only provides the same functionality as goto.
|
# ? Sep 27, 2010 18:22 |
|
Right now I am very tempted to send an email around my company:The email I am not sending posted:If you have marked your page as being XHTML and you are getting strange errors in Chrome such as "expected ;" the problem is that you haven't escaped one of the following characters &<>'". Chrome actually validates XHTML which means you have to make your XHTML parse as valid XML. This is not rocket science people, the next person I see puzzling over a bug that was caused by <a href="http://somedomain/path?aparam=avalue&anotherparam=anothervalue"> I will loving kill you.
|
# ? Sep 27, 2010 18:31 |
|
Zombywuf posted:Right now I am very tempted to send an email around my company: e: I just tested it; HTML with the wrong doctype is parsed as HTML, which means your coworkers have roughly the IQ of grass. Send the hell out of that email. TOO SCSI FOR MY CAT fucked around with this message at 18:58 on Sep 27, 2010 |
# ? Sep 27, 2010 18:50 |
|
Otto Skorzeny posted:There's a semantic spat to be had here about whether scalar variables in Perl have types and whether perl's concept of SV's and PV's constitute datatypes, but I'll instead say that you probably also have a bone to pick with ANSI C's handling of equality between ints and floats: I'm not as mussed about it in statically typed languages, because then the type checker can ensure that (a) the coercion will never fail at runtime and (b) no information is lost - in the case of C, for example, short int == long int will upcast the lhs to a long int, int == float will upcast it to a float, and int == char * is an error (or at least a warning). In a dynamically typed language no such guarantees can be made, so the possibility exists for something that works most of the time, but fails on certain input as the coercion fails at runtime - or something that works all of the time even when it should fail and report invalid input. RankWeis posted:Yeah, unfortunately, I was posting from my iPad so google and a terminal were too complicated to actually test anything out. But I recall that languages that do this type of comparison usually have a 'strict' comparison to go along with it, and I thought python was one of them Most dynamically typed languages are nonetheless strongly typed and, consequently, tend not to pull this. It mostly seems to be a feature of weakly typed languages like Perl or TCL. It may come as no surprise that my preference is for strongly+statically typed languages.
|
# ? Sep 27, 2010 19:09 |
|
Here's some type-related fun I came across in some vendor code today:code:
|
# ? Sep 27, 2010 19:13 |
|
So wait, is it calling Number() on something that's already numeric? Or are they not only using systems hungarian, but lying about the type?
|
# ? Sep 27, 2010 19:22 |
|
ToxicFrog posted:So wait, is it calling Number() on something that's already numeric? Or are they not only using systems hungarian, but lying about the type? The inputs to this method come from SELECT elements, so technically that is a String always. There's a lot of weird stuff like this, which I gather comes form said vendor being a .NET developer who had to do a little bit of javascript.
|
# ? Sep 27, 2010 19:29 |
|
ToxicFrog posted:int == float will upcast it to a float, Bit of a nitpick, but this is not true. A 32-bit int can hold more distinct integer values than a 32-bit float can, so just casting the int to float wouldn't work.
|
# ? Sep 27, 2010 20:28 |
|
Hammerite posted:I don't see what you mean. Yes, do { ... } while (false) is another good example, although as far as I am aware it only provides the same functionality as goto. Sorry, I thought we were playing "seemingly odd but legitimate uses of loops", not "heh everything is a goto". PS How is what you quoted a goto?
|
# ? Sep 27, 2010 21:00 |
|
Hammerite posted:I think this could be defensible, depending on what exactly it's being used to do. Similar to how while (true) {...} can be a useful control structure. I challenge thee to provide an example.
|
# ? Sep 27, 2010 21:08 |
|
Hammerite posted:Yes, I have. There is no hypothetical "maybe this construct could sometime, someday be useful — I'm going to put this feather in my cap!" situation. Not only did the snippit say that the loop goes through just one iteration, if i were modified in the body, in any fashion, it would be a classifiable mess. I guarantee you that I can come up with a clearer version of any possible replacement for "//do some stuff, guess how many times" that involves modifying i.
|
# ? Sep 27, 2010 21:32 |
|
pokeyman posted:Sorry, I thought we were playing "seemingly odd but legitimate uses of loops", not "heh everything is a goto". Well, it could be that there is a use for do { ... } while (false) that has not occurred to me, but my own use of it has been limited to error checking; as in code:
I don't know what you mean by "heh everything is a goto". I don't think I've said anything to that effect.
|
# ? Sep 27, 2010 21:34 |
|
Mustach posted:The point is that they implemented the if statement with a for. I'm sorry, but I don't understand your reasoning. How is that in any way an implementation of the if control structure?
|
# ? Sep 27, 2010 21:40 |
|
Lysandus posted:I challenge thee to provide an example. I cannot.
|
# ? Sep 27, 2010 21:44 |
|
Lysandus posted:I challenge thee to provide an example.
|
# ? Sep 27, 2010 22:02 |
|
while(true) is great when you need to do something like "read n bytes from this socket"; sure, it's possible to encode this loop with for, but an infinite loop combined with break or return is much clearer. do { } while(0) is really only useful for preprocessor macros. That use of it for error handling is obscene, just use goto, gently caress, it doesn't bite.
|
# ? Sep 27, 2010 22:36 |
|
Janin posted:do { } while(0) is really only useful for preprocessor macros. That use of it for error handling is obscene, just use goto, gently caress, it doesn't bite. I would use goto, but it isn't available in PHP until version 5.3, and I want my scripts to be portable to hosts running versions 5.0 and above.
|
# ? Sep 27, 2010 22:53 |
|
Quote is not edit
|
# ? Sep 27, 2010 22:54 |
|
Hammerite posted:I would use goto, but it isn't available in PHP until version 5.3, and I want my scripts to be portable to hosts running versions 5.0 and above.
|
# ? Sep 27, 2010 22:58 |
|
Hammerite posted:php I had no idea we were talking about PHP. My apologies.
|
# ? Sep 27, 2010 23:46 |
|
pokeyman posted:I had no idea we were talking about PHP. My apologies. For myself, I didn't think what we were talking about was specific to PHP - what's different in other languages? Tell me more.
|
# ? Sep 28, 2010 00:53 |
|
The skeleton code for my current programming assignment is certainly horrific. Among the things about it I hate, there are such wonderful things as: 1) Being forced into using java.nio when multithreading would be so very much easier (and there wouldn't even be data shared between threads at any time, so I can't see a disadvantage to using it)! 2) A parsing method, to retrieve the hostname from an HTTP header, which returns 'void'. Since we are explicitly not allowed to change the provided interface, I've made this method set a member variable which is then read by the method that calls it, which is a coding horror in and of itself. Of course, it could just return String, in which case everything would be simple. 3) To make the marking easier, they've split the code into three different methods which (theoretically) can be tested on their own if the entire thing doesn't work as intended. Of course, this means that various data must be stored in member variables since the interfaces are fixed and they don't provide all the necessary parameters. Besides, if not all methods work as intended, the entire thing will be completely hosed anyway. I have a suspicion that this code may have been written by the TA who couldn't figure out why an extra curly brace was causing an error, nor why variable.socket is different from variable.socket().
|
# ? Sep 28, 2010 00:54 |
|
quote:do { } while(0) I use this on occasion to create a scope from which my objects will be destructed automatically after completion. For example: do { CRenderingContext c(Game()->GetRenderer()); c.SetBlend(BLEND_ALPHA); CRootPanel::PaintTexture(m_iGraphic, 10, 20, 30, 40); } while (false); // Since CRenderingContext pops the blend state in its destructor, any painting here won't have alpha blending. In my experience a simple { } didn't do this, the do while false bit was needed. Perhaps there is a better way?
|
# ? Sep 28, 2010 01:14 |
|
Vino posted:I use this on occasion to create a scope from which my objects will be destructed automatically after completion. For example:
|
# ? Sep 28, 2010 02:10 |
|
schnarf posted:Just doing {} should do that. Odd. In my limited tests it did not. Perhaps more investigation is needed.
|
# ? Sep 28, 2010 02:19 |
|
Hammerite posted:For myself, I didn't think what we were talking about was specific to PHP - what's different in other languages? Tell me more. I am totally unfamiliar with PHP, but why wouldn't you just use an else if? That break in each of the if blocks makes me want to check that it exists in all of them or if there is some kind of bizzaro override.
|
# ? Sep 28, 2010 02:52 |
|
|
# ? May 25, 2024 13:39 |
|
PT6A posted:2) A parsing method, to retrieve the hostname from an HTTP header, which returns 'void'. Since we are explicitly not allowed to change the provided interface, I've made this method set a member variable which is then read by the method that calls it, which is a coding horror in and of itself. Of course, it could just return String, in which case everything would be simple. I have to deal with a 3rd party API which does something similar. There's a function to get certain information from devices, which is void, so how do you actually get the info? Why it's simple: 1. You give the instance that represents the device a GetInfoCallback. 2. You call RequestInfo, which returns immediately. 3. The callback is called on a separate thread. 4. In the callback you call GetInfo, which gives you the last requested info. If you have two simultaneous info requests, you'll get both results, but there's no way to tell which is which. Oh, and if an error occurs, then the callback is never called, but you're also never notified that something went wrong.
|
# ? Sep 28, 2010 08:31 |