- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
I think that he thinks what you didn't think that he thought.
While we don't really know what YOU thought, we can only guess. The fact is, though, that assignation means "the act of assigning or the assignment made" (according to Webster). Although this term is not generally accepted as being part of the programmer's nomenclature, it was more or less correct.
Admin
[quote user="Someone You Know"][quote user="Denis Troller"]In VB the rules are simple:
'=' is both the equality and assignation operator, depending on context. ... ---> 3) If this is a statement, then it is assignation
There is NO multiple assignation in VB...Assignation are not L-Values.
...
In that case, the first = is clearly a statement and thus an assignation.[/quote]
You keep using that word. I do not think it means what you think it means.[/quote]
'=' is both the equality and assignation operator, depending on context. ... ---> 3) If this is a statement, then it is assignation
There is NO multiple assignation in VB...Assignation are not L-Values.
...
In that case, the first = is clearly a statement and thus an assignation.[/quote]
You keep using that word. I do not think it means what you think it means.[/quote]
I think that he thinks what you didn't think that he thought.
While we don't really know what YOU thought, we can only guess. The fact is, though, that assignation means "the act of assigning or the assignment made" (according to Webster). Although this term is not generally accepted as being part of the programmer's nomenclature, it was more or less correct.
Admin
Are there performance benefits to doing this instead of the following?
i-=(i%j)
Admin
Admin
Oh, you're right. I forgot that in VB, parentheses are used both for calling functions and for accessing array elements, so you can better confuse the two.
Admin
Cool! Well thought out. Well reasoned. It would be perfect if you had just mentioned how Ada is superior to all other languages. :)
Admin
INCONCEIVABLE!!!
Admin
You actually consider that a joke?
Admin
This is incorrect on 2 points.
This has nothing to do with ASP, it is specific to VBScript which is the most common language used for ASP pages. ASP supports any Active Scripting language: VBScript, JScript, Perl, et al.
The fact that all variables are variant merely abstracts data type, it doesn't remove it. Variant data has a subtype field that indicates the underlying data type of the variable.
Admin
As far as I'm aware, option 1 is correct. Certainly that's the case up to VB6; .NET I'm not so sure about...
The compiler would ignore the parentheses in x = (y = 3) since that is the only legal place they could go:
(x = y) = 3
is an invalid statement. No casts in VB, so no brackets at the start of a line!!
Therefore, x = (y = 3) is the functional equivalent of
x = y = 3
which definitely does the same as x = (y == 3) in C etc.
Admin
Admin
Admin
Admin
Admin
Akatherder said: As far as practical use, I've never actually seen '' used (on purpose).
Been there, done that.
Any time you want to divide integers and get an integer, it's at least got a good shot - assuming you don't mind the rounding rules - of being The Right Thing.
(I mean, sure, you could use normal division and then cast to an integer, but why bother, when you have a nice integer division operator built in?)
Such tasks, for example, being formatting strings for a fixed-width-font printer. Or resizing a control in-code. Location and width are all integers, too.
Admin
I absolutely hate working on other people's code. Usually, any program you come across has had at least half a dozen coders throughout the years. Each one with their unique take on the language, the purpose, and commenting. I would infinitely better like to create something from scratch than to try and wrap my head around how someone thought.
Admin
Although at least that would doom VB, Java, Perl, Python, Ruby, Groovy, and the rest of that crap.
Flames welcome.
Admin
Oh man... I programmed in VB before and never knew about the . Luckily, as a 7th grader, my code never really went production... unless you count the board game I submitted for a book report :P
Admin
It could possibly be like a REALLY bad modulus like function.
For example, assuming integers, when you divide istart by ioffset, you'll floor the integer divide. Then, when you muliply it back, you get whatever the next rounded down divisible value would be.
Another way to state it is (in C / C++ / Java / etc.): if ((istart % ioffset) == 0)
Admin
Admin
Admin
Interestingly, hungarian notation in its original form, didn't incode the type of the var, but the semantics of the var. It's only since a few corporations "mistook" the idea. It probably occured due to an abundance of management savy, managers, who have no equal standing in coding practices.
It was meant to be more like.
struct LinkedList_Link { LinkedList_Link* next_link; <some type> <appropriatly explicit name> ... ... Bookings roomBookings[20]; int roomBookingsCount; };
Admin
Because the other slash was already taken.
Admin
"what the --?!"
Beats me. Reading this site, I'll never guess what the -- stands for.
Admin
Captcha: No, I registered :)
Admin
Admin
Shouldn't that be
"worse than --?!"
I don't care about the name, It's just a name, people. If you so dislike it, set up your browser to replace any instance of the name and logo with the old one :)
Admin
Gee, I imagine Tcl without library functions.
If there was a CAPTCHA, it would be: muahahaha.
Admin
I believe the first Microsoft BASIC actually was the Altair BASIC, not the Commodore one.
Admin
/Still don't believe you think we care.
Admin
Well... kinda:
Admin
(object.property).method()
Not legal, but perfectly reasonable to want to do even with "no casts" - casts are certainly not the only reason to want brackets at the start of a line.
Admin
Right. for it to make sense (as the story claims it does), it would have to be actually doing something instead of testing an always-true condition.
captcha: ewww
Admin
Why not just:
int id_x = Mouse.X - (Mouse.X MOD 16); int id_y = Mouse.Y - (Mouse.Y MOD 16); Bitmap tile = (Bitmap) tiles[id_x][id_y]; //I'm not sure that is how you had the array hashed...
Admin
umm didn't think of it? I didn't know there was a MOD supported in C# really... would that actually work? Because what I am getting is the top left corner of the tile offset from the top left corner of the map...
Admin
int id_x = Mouse.X - (Mouse.X % 16);
VB's MOD converts both operands to INT before performing the modulus; in C#, type conversion works as normal, so if either operand is a double, both are converted first, and a double is returned.
i.e., 5 % 2.2 = 0.6 So, I think this will still give the desired results, although you might have to cast it to an int. (The VB example before was relying on the truncating to an int, since its MOD always returns an integer).
Admin
Floor(X/16) * 16 ==> find the largest integer multiplier of 16 that is less than X X - (X % 16) ==> Take X and subtract any portion that would be a remainder if divided by 16, or the largest integer multiplier of 16 that is smaller than X.
Admin
If you're still about, Cyrus, Mike's just explained it better than I could.
Admin
Same as: If (iStart = iOffset) Or (iStart = 0) And Not(iOffset = 0) See how much longer this one is?!?! mmmmmmmm.... captcha
Admin
There's rarely a reason why you HAVE to do an assignment within the same actual line of code as the comparison, so why not remove the possibility of ambiguity? The only reason it's confusing is because people are used to the assignment behaviour from other languages.
Admin
Admin
I agree with you that, intuitively it makes sense to have different operators for different semantics.
Now the problem with that in C (and derivative) is that the two operators are actually very easy to exchange (especially in favor of a typo), and the since the language actually allows using the = operator in a condition, this can lead to enormous mistakes which are not easy to find. There was a a reason for that because of the philosophy of minimal cost and high performance of the language (using one operation instead of two). It maps nicely to, for example, the way a microprocessor handles this (at least on a 68K as far as I know).
Using the same operator, on the other hand, makes the compiler determine what the intended use is. It does not make it more difficult to read when you know you're looking at VB code since it cannot be anything else than a comparison. You don't have to ask yourself what the compiler is going to understand, if you want. On the other hand, if you're not trained in VB, it's hellishly confusing, but so is C's use of assignation in conditions for someone not using C all day.
When you get down to it, it always seemed a weird design choice to me that an assignment should carry a value, but that's the way it is. Again, back to "matter of taste" and to "get used to your language".
Admin
Personally I think the language Turing has the assignment/comparison problem licked: just like mathematical proof conventions it uses := for assignment and = for comparison. From my point of view = is a comparison, and comparison and assignment are fundamentally different, so := is a nice way to denote assignment.
I have to use VB.NET at work (company-wide standard), and I used C++ and Lisp in university and I use Java and Perl for my own projects. I started with Javascript and QBASIC. So I have a wide variety of languages to compare against, and my personal preference is the C-style, even though I learned with QBASIC, just because I find the distinction between assignment and comparison to be more intuitive and easier to read/understand than using the same operator for two different tasks.That's just me, though. I don't really hate VB because of the =/== issue. I dislike it for other reasons entirely.
Admin
no,
is far better in a non-optimizing environment.Admin
Personally I prefer the explicitness of C/C++. I consider the way that VB does it to be the ambiguous way. When dealing with algorithms, you'll likely come in contact with a lot of code which would be overall cleaner using both assignments and comparisons on one line. The consistency of C in relation to such integral concepts as L-values allows for clean, efficient (in speed and line count), and readable code.
I prefer a language that penalizes my ignorance rather than one that glazes over it. It helps keep me more aware of every line of code that I write.
Admin
I never knew about ""
I always used Cint(x/y)
You learn somthing new every day..
Admin
It actually is not the same thing. The CInt(x/y) rounds the result of the floating point division. The \ operation gives you the integer part of your division.
As an example, take 21 / 9 21/9 = 2.3333333... CInt(21/9) = 2 21\9 = 2 It seems to work.
But take 19 / 7 19/7 = 2.714286.... Cint(19/7) = 3 19\7 = 2
\ Is not a simple shortcut to rounding. And it works only on integer (or long) operands. VB will yell if you try to use it on floating point operands.
Admin
Yeah, I came around that solution for catching those stupid errors, but since I don't write C code very often, I quickly forgot about it :) And I don't like having to write things "backwards" (my point of view entirely) to catch mistakes because of the language :) It seems much more logical to me to say "if x equals 5" and write "if x = 5" than to say "if x equals 5" and write "if 5=x" (or to say "if 5 equals x"). But on the other hand, I once wrote a fair amount of RPL code on HP 48 calculators and I was able to wrap my mind around it at the time. It just was not easy to understand after two weeks not reading the code.
And I agree with you that using 2 different operators is good. The Turing (and Pascal) operator works for me too. But then I don't think you can use assignments as conditions in those, and that is where the "problem" comes from with C. It's almost as easy to forget the ":" in Pascal-like assignment as it is to forget the "=" in C. But C will compile it and you'll end up with something entirely different from what you meant. The only way around it is to "change your way of thinking" and write the comparison in reverse, as you mentioned above.
Again, as you said, not a reason to hate the language. Just something to gently bitch about on forums :D
Admin
There's a compiler setting that will warn about assignment statements in if statements.
Doing the assignment in the if statement is slightly more compact, and may possibly result in slightly more efficient code, since the value is already in a register, and doesn't have to be read from memory.
Admin
I think the page displays data 20 rows at a time, but I'm confused about whether the page can only be scrolled down 20 rows at a time - in that case, the starting row would always be a multiple of 20, and there would be no need to check if it is aligned - or if it can be scrolled in smaller increments.
It's either checking that the first row on the screen is a multiple of the page size, or it's checking whether the total number of rows is a multiple of the page size, I think. I suspect the variable names may be slightly misleading.