• Someone you may not know (unregistered) in reply to Someone You Know
    Someone You Know:
    Denis Troller:
    In VB the rules are simple:
    1. '=' is both the equality and assignation operator, depending on context. ... ---> 3) If this is a statement, then it is assignation

    2. 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.

    You keep using that word. I do not think it means what you think it means.

    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.

  • Someone I don't think that you know (unregistered) in reply to Someone You Know

    [quote user="Someone You Know"][quote user="Denis Troller"]In VB the rules are simple:

    1. '=' is both the equality and assignation operator, depending on context. ... ---> 3) If this is a statement, then it is assignation

    2. 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]

    1. '=' is both the equality and assignation operator, depending on context. ... ---> 3) If this is a statement, then it is assignation

    2. 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.

  • (cs) in reply to Mike
    For those not aware, in a language like C, that'd be perfectly logical. Assuming that everything is an int, then the line

    i=j*(i/j)

    can be used to set i to the greatest multiple of j that is less than or equal to i.

    Are there performance benefits to doing this instead of the following?

    i-=(i%j)

  • (cs) in reply to Someone you may not know
    Someone you may not know:
    Someone You Know:
    Denis Troller:
    In VB the rules are simple:
    1. '=' is both the equality and assignation operator, depending on context. ... ---> 3) If this is a statement, then it is assignation

    2. 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.

    You keep using that word. I do not think it means what you think it means.

    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.

    It's fun to watch that joke soar far above your head.

  • AdT (unregistered) in reply to Jeff
    Jeff:
    AdT: you mention the function "aResults". I'm sure that's not a poorly-named function, it's an equally poorly named array.

    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.

  • Juenemann (unregistered) in reply to Denis Troller
    Denis Troller:
    I guess WTF would not be the same if people were to stop arguing about VB's syntax.

    Now if those same people could spare one hundredth of the energy they use for complaining, and use it to actually try to understand how VB operators work, that would be a nice change. Obviously this is not going to happen since people have been trying to explain that for as long as I can remember on this site.

    You don't like using the same operator for equality and assignation? Fine, I don't like having the opportunity to shoot myself in the foot every time I write a condition by forgetting an equal sign. But you don't see people like me complaining about it every third post. VB syntax on this makes perfect sense, as far as VB programmers are concerned (and please, VB programmers actually DO now other languages).

    It seems to me that the more we see VB stuff, the quicker the focus changes from the code to the fact that people don't even try to understand VB's syntax and forget about what the article is about.

    In any case, as the saying goes: a good programmer will be good whatever the language. A bad one will be bad whatever the language. You can write WTFs (original meaning) in whatever language you choose, they all offer plenty of ways to shoot yourself in the foot. Just because you can't be bothered trying to undertand the syntax (which would require about 1 minute of half concentration) does not mean the language is the WTF.

    If you want to discuss the pros and cons of VB (and then please state the version because VB 6 and .NET are almost as different as C and C++) then fine, be my guest, I'll entertain you. But try to get your facts straight and don't argue on stupid syntax differences that don't matter.

    This is why I prefer architectural WTFs. They are usually a much better insight into humanity's insanity.

    Sorry, needed to vent this time.

    Cool! Well thought out. Well reasoned. It would be perfect if you had just mentioned how Ada is superior to all other languages. :)

  • Sicilian (unregistered) in reply to joe.edwards
    Someone you may not know:
    Someone You Know:
    Denis Troller:
    In VB the rules are simple:
    1. '=' is both the equality and assignation operator, depending on context. ... ---> 3) If this is a statement, then it is assignation

    2. 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.

    You keep using that word. I do not think it means what you think it means.

    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.

    It's fun to watch that joke soar far above your head.

    INCONCEIVABLE!!!

  • [email protected] (unregistered) in reply to joe.edwards
    It's fun to watch that joke soar far above your head.

    You actually consider that a joke?

  • RDD (unregistered) in reply to Scott Duensing
    Scott Duensing:
    Float? In old ASP code? Surely you jest! Everything in "classic" ASP is a "variant". We'll have none of those confusing "type thingies" here!

    Scott

    This is incorrect on 2 points.

    1. 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.

    2. 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.

  • Adam (unregistered) in reply to Sgt. Preston

    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.

  • (cs) in reply to [email protected]
    It's fun to watch that joke soar far above your head.

    You actually consider that a joke?

    Consider our surroundings. The bar is low, and the punters desperate.

  • Cornered (unregistered) in reply to Someone You Know
    Someone You Know:
    Denis Troller:
    In VB the rules are simple:
    1. '=' is both the equality and assignation operator, depending on context. ... ---> 3) If this is a statement, then it is assignation

    2. 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.

    You keep using that word. I do not think it means what you think it means.

    www.m-w.com allows "the act of assigning or the assignment made" for "assignation". I've only ever known the word as a synonym for "tryst".

  • (cs) in reply to Mike
    Mike:
    For those not aware, in a language like C, that'd be perfectly logical. Assuming that everything is an int, then the line

    i=j*(i/j)

    can be used to set i to the greatest multiple of j that is less than or equal to i.

    Which would only make sense if the line read
    iOffset = iStart * (iOffset/iStart)
    unfortunately.

  • (cs) in reply to Evo
    Evo:
    akatherder:
    \ is integer division (Divide and the remainder disappears) / is normal division (Divide and the expected result is returned)

    PLEASE tell me you're kidding me...... Damn I hate VB :-|

    Don't be provincial. (At least some versions of) Algol made the same distinction, calling the operators / and //. Personally, I find C's "bait, cast and hope" much more annoying - if any language gets it right, it's ANS Forth - but that illustrates only the vagaries of personal taste.

  • Sigivald (unregistered)

    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.

  • Jerim (unregistered)

    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.

  • (cs) in reply to Jerim
    Jerim:
    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.
    Goodbye, library functions!

    Although at least that would doom VB, Java, Perl, Python, Ruby, Groovy, and the rest of that crap.

    Flames welcome.

  • hachu (unregistered) in reply to akatherder

    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

  • CM (unregistered)

    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)

  • (cs) in reply to CM
    CM:
    For example, assuming integers, when you divide istart by ioffset, you'll floor the integer divide.
    Thank you so much, CM. I wasn't sure after the first twelve explanations, but seeing you writing the exact same thing has finally caused me to overlook the bit in the article that states that iOffset was a multiple of iStart, rather than vice versa, and understand that this must be what was meant. My life in enriched, and it is all your doing.
  • (cs) in reply to Jerim
    Jerim:
    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.
    Never mind, you'll get over that once you've graduated.
  • (cs) in reply to number6
    number6:
    AdT:
    (The Hungarian notation would suggest this, but given the overall quality of the code, I would not be surprised to read something like "Dim iMyInteger As Double".)

    That is precisely why Hungarian notation is a bad idea.

    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; };

  • Frost (unregistered) in reply to My Name
    My Name:
    To do integer division in VB you use the backslash '\'. Don't know why.

    Because the other slash was already taken.

  • Oh fuck (unregistered)

    "what the --?!"

    Beats me. Reading this site, I'll never guess what the -- stands for.

  • (cs) in reply to Denis Troller
    Denis Troller:
    <snip>

    In any case, as the saying goes: a good programmer will be good whatever the language. A bad one will be bad whatever the language. You can write WTFs (original meaning) in whatever language you choose, they all offer plenty of ways to shoot yourself in the foot. Just because you can't be bothered trying to undertand the syntax (which would require about 1 minute of half concentration) does not mean the language is the WTF.

    <snip>

    Sorry, needed to vent this time.

    Hear hear! We all have our prefered language, let's honor those that use others.

    Captcha: No, I registered :)

  • Rhialto (unregistered) in reply to Timothy Baldridge
    Timothy Baldridge:
    This is a carry-over from the old days (QBasic, GWBasic, etc.) when doing a floating point divide was more expensive than a integer one (actually it it still is, but it's all so fast, it doesn't matter anyway).
    Actually, in (on of) the first Microsoft Basic, also known as Commodore Basic, operations on integers are *slower* than on floating point, because for each operation they are converted to floating point, the operation is done, and the result is converted back.
  • (cs) in reply to Stormy
    Stormy:
    Shouldn't that be..

    "oh you've got be kidding me," "why whould they do that," "worse than failure --?!"

    /Still don't like the name change.

    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 :)

  • (cs) in reply to real_aardvark
    real_aardvark:
    Goodbye, library functions!

    Although at least that would doom VB, Java, Perl, Python, Ruby, Groovy, and the rest of that crap.

    Flames welcome.

    Gee, I imagine Tcl without library functions.

    If there was a CAPTCHA, it would be: muahahaha.

  • (cs) in reply to Rhialto
    Rhialto:
    Actually, in (on of) the first Microsoft Basic, also known as Commodore Basic, operations on integers are *slower* than on floating point, because for each operation they are converted to floating point, the operation is done, and the result is converted back.

    I believe the first Microsoft BASIC actually was the Altair BASIC, not the Commodore one.

  • (cs) in reply to Stormy
    Stormy:
    /Still don't like the name change.

    /Still don't believe you think we care.

  • Nyuserre (unregistered) in reply to Kain0_0
    Kain0_0:
    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.

    Well... kinda:

    Wikipedia (so it must be true):
    While most of the prefixes Simonyi suggested are semantic in nature, not all are. The following are examples from the original paper: [1]
    * pX is a pointer to another type X; this contains very little semantic information.
    * d is a prefix meaning difference between two values; for instance, dY might represent a distance along the Y-axis of a graph, while a variable just called y might be an absolute position. This is entirely semantic in nature.
    * sz is a null- or zero-terminated string. In C, this contains some semantic information because it's not clear whether a variable of type char* is a pointer to a single character or an entire string.
    * w marks a variable that is a word. This contains essentially no semantic information at all, and would probably be considered Systems Hungarian.
    * b marks a byte, which in contrast to w might have semantic information, because in C the only byte-sized data type is the char, so these are sometimes used to hold numeric values. This prefix might clear ambiguity between whether the variable is holding a value that should be treated as a letter (or more generally a character) or a number.
    
  • Random832 (unregistered) in reply to Adam
    No casts in VB, so no brackets at the start of a line!!

    (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.

  • Random832 (unregistered) in reply to Welbog
    Welbog:
    Random832:
    if iStart = iOffset*(iStart/iOffset) then value = aResults(2, iOffset*(iStart/iOffset)) summary = summary & ". " & value end if

    While Hannes wasn't able to provide any insight into the purpose of that IF statement, he did notice out that iStart is always twenty and iOffset is always a multiple of twenty. But it wasn't until his coworker replied "oooh, well that makes sense, then" that he realized how much he had truly lucked out.

    That code was clearly not originally in VB, because that code would not do what the story claims it does in VB - the operator required for that would be , not /.
    Wait, what? The story doesn't claim anything about the code other than "it makes sense"...

    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

  • (cs) in reply to sol
    sol:
    I do something like this to find out what part of the map the mouse is over...

    I have an array of stuff that I need to access when the user clicks some where. The map is a grid of 16x16 squares(tiles)...

    int id_x = Convet.ToInt32(Math.Floor(Mouse.X/16) * 16); int id_y = Convet.ToInt32(Math.Floor(Mouse.Y/16) * 16); Bitmap tile = (Bitmap)tiles[id_x][id_y]; //I'm not sure that is how I have the array hashed...

    That isn't exact code... but that is the general idea... I think I pulled out most of my hair before I said you idiot Floor the value....

    captcha: smile.. I'll try but it makes my face hurt

    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...

  • sol (unregistered) in reply to vertagano
    vertagano:
    sol:
    I do something like this to find out what part of the map the mouse is over...

    I have an array of stuff that I need to access when the user clicks some where. The map is a grid of 16x16 squares(tiles)...

    int id_x = Convet.ToInt32(Math.Floor(Mouse.X/16) * 16); int id_y = Convet.ToInt32(Math.Floor(Mouse.Y/16) * 16); Bitmap tile = (Bitmap)tiles[id_x][id_y]; //I'm not sure that is how I have the array hashed...

    That isn't exact code... but that is the general idea... I think I pulled out most of my hair before I said you idiot Floor the value....

    captcha: smile.. I'll try but it makes my face hurt

    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...

    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...

  • (cs) in reply to sol
    sol:
    vertagano:
    sol:
    I do something like this to find out what part of the map the mouse is over...

    I have an array of stuff that I need to access when the user clicks some where. The map is a grid of 16x16 squares(tiles)...

    int id_x = Convet.ToInt32(Math.Floor(Mouse.X/16) * 16); int id_y = Convet.ToInt32(Math.Floor(Mouse.Y/16) * 16); Bitmap tile = (Bitmap)tiles[id_x][id_y]; //I'm not sure that is how I have the array hashed...

    That isn't exact code... but that is the general idea... I think I pulled out most of my hair before I said you idiot Floor the value....

    captcha: smile.. I'll try but it makes my face hurt

    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...

    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...

    Ah. I didn't notice it was in C#...

    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).

  • (cs) in reply to sol
    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...
    It should be the same result.

    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.

  • Matt (unregistered) in reply to Mike
    Mike:
    For those not aware, in a language like C, that'd be perfectly logical. Assuming that everything is an int, then the line

    i=j*(i/j)

    can be used to set i to the greatest multiple of j that is less than or equal to i.

    of course, if VB treats int/int as a double, as pointed out above, then all bets are off...

    If you're still about, Cyrus, Mike's just explained it better than I could.

  • tonsofpcs (unregistered)

    Same as: If (iStart = iOffset) Or (iStart = 0) And Not(iOffset = 0) See how much longer this one is?!?! mmmmmmmm.... captcha

  • prof_hobart (unregistered) in reply to Volmarias
    Volmarias:
    zip:
    Single equals sign IS the equality check in VB. Party on!

    And you've just hit upon one of the many reasons why I hate VB.

    As I asked last time this got mentioned (with no reply), why is it better having a language where forgetting to put == rather than = will create a bug that's usually hell to catch?

    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.

  • (cs) in reply to prof_hobart
    prof_hobart:
    Volmarias:
    zip:
    Single equals sign IS the equality check in VB. Party on!
    And you've just hit upon one of the many reasons why I hate VB.
    As I asked last time this got mentioned (with no reply), why is it better having a language where forgetting to put == rather than = will create a bug that's usually hell to catch?

    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.

    How about the fact that assignment and comparison are two completely different operations and should therefore not share an operator?

  • (cs) in reply to Welbog

    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".

  • (cs) in reply to Denis Troller
    Denis Troller:
    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).
    There's an easy way to avoid getting bitten by accidentally typing = instead of ==: make sure that, when comparing two things, the first is unassignable. `if (5 = n)` is a compiler-time error (if I recall correctly - this isn't a mistake I made more than once or twice so I don't recall exactly what happens).

    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.

    Denis Troller:
    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".
    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.

  • bill (unregistered) in reply to Arancaytar
    Arancaytar:
    For those not aware, in a language like C, that'd be perfectly logical. Assuming that everything is an int, then the line

    i=j*(i/j)

    can be used to set i to the greatest multiple of j that is less than or equal to i.

    Are there performance benefits to doing this instead of the following?

    i-=(i%j)

    no,

     i -= (i % j); 
    is far better in a non-optimizing environment.
  • Chaz (unregistered) in reply to prof_hobart

    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.

  • brainlord mesomorph (unregistered) in reply to akatherder

    I never knew about ""

    I always used Cint(x/y)

    You learn somthing new every day..

  • (cs) in reply to brainlord mesomorph

    Comment OnMultiplied Denomination Reply To Comment Re: Multiplied Denomination 2007-06-28 07:46 • by brainlord mesomorph I never knew about ""

    I always used Cint(x/y)

    You learn somthing new every day..

    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.

  • (cs) in reply to Welbog
    There's an easy way to avoid getting bitten by accidentally typing = instead of ==: make sure that, when comparing two things, the first is unassignable. `if (5 = n)` is a compiler-time error (if I recall correctly - this isn't a mistake I made more than once or twice so I don't recall exactly what happens).

    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.

    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

  • Alan Balkany (unregistered)
    As I asked last time this got mentioned (with no reply), why is it better having a language where forgetting to put == rather than = will create a bug that's usually hell to catch?

    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.

    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.

  • Darwin (unregistered)

    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.

Leave a comment on “Multiplied Denomination”

Log In or post as a guest

Replying to comment #:

« Return to Article