Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
E

Eric A Carter

@Eric A Carter
About
Posts
4
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Flappy Bird Pulled
    E Eric A Carter

    Angry Birds, Flappy Bird...yeah, it seems people are going cuckoo over bird-based games. I blame Duck Hunt.

    Ooh, hey up, I've got some code for summat like that I wrote about 20 years ago...somewhere... [rifles through boxes of 3.5" disks and ancient HDDs]

    The Insider News com

  • Are there reasons for beginner programmers to learn C ?
    E Eric A Carter

    I couldn't agree more, and here's a perfect example of why. Maximilien said in an earlier post: " ... std::string s("hello world"); ... it is efficient." That depends on your definition of 'efficient' and the context in which a class such as std::string is used. A quick check of 'std::string s("hello world")' in the debugger reveils that the string capacity is 4 bytes longer than the string contents (not counting 0 termination added when s.c_str() is used to dereference to char*). For a single static std::string, that's acceptable, but I know from my own experience that, say, a std::vector> containing several thousand static strings results in a lot of wasted empty space that could be better dealt with - and an order of magnitude faster - by using a pool-indexed system, which can be easily implemented in either ANSI C or C++; I wrote a C++ class specifically with this issue in mind years ago and still use an updated version of it to this day. Using predefined classes/templates from std or Boost is all well and good, but if you don't know how it all works under the hood, obscure bugs, memory leaks and the like can (and will) creep into your code because you made incorrect assumptions about those classes/templates. For the most part, I still like to roll my own codebase (I use std::vector but little else from std, and Boost doesn't exist on my machine, period), because I like to know what my code is doing - and/or not doing - to my data. I first learned to code (way back when) in pseudocode, then BASIC, then Pascal, then C, then C++. That 'natural progression' gave me the tools required to put algorithms and design above implementation and style right from the get-go, a skill that many younger coders seem to lack.

    The Lounge learning c++ oop performance

  • From where should the index start?
    E Eric A Carter

    1. I stand corrected - I just ran a few simple tests which prove your case. I still hold that in certain situations, 0-based can produce faster machine-level code than non-0; clearly this is not one of them, due to runtime recalculation concerns. 2. Technically you are correct, but unless there are some really pedantic people out there, I know of noone who would say they just turned 'X years and X weeks' old on thier birthday (depending on how many weeks they gestated for - not everyone spends 9 months in the womb). In some ways, the difference between 0 and 1 in this discussion is moot, because eventually everything comes down to 0-based ADDRESSING in machine code anyway. As far as 'indexing' (an entirely different thing to 'addressing', mind you) in a high-level language is concerned, there are 3 basic options which are entirely preference-dependant: a. 0-based indexing, mimicing addressing to nullify/trivialise index-to-address calculations; b. 1-based indexing, mimicing the human perception of quantity; c. N-based indexing, allowing the user to specify the base index to complement a particular indexing system used 'natively' by a code block. Personally, I prefer the 0-based approach, because the machine works that way for addressing anyway, and any other indexing system can be emulated (for almost no cost these days) by simply adding an offset value: 1-based = index + 1, 12-based = index + 12, -345-based = index + -345; not hard at all. If I was to write a high-level language of my own however, I admit I'd probably code in the option of preset array offsets, with a default offset of 0 if one wasn't specified at array allocation. All of these options have been used to great effect in many languages over the years, and all of them have pros and cons. If you're writing a high-level/scripting language, your best bet is to go with the indexing system that works best for you first, and if others like it, that's a bonus.

    The Lounge question php database design help

  • From where should the index start?
    E Eric A Carter

    If I am reading this correctly, you are stating that VB.NET has to recalculate the value of (ListBox1.Items.Count-1) through EVERY ITERATION of the loop; does anyone else see the flaw in that logic? The trouble with your example is this: you are making the assumption that the compiler will not optimise the above code at compile time. If you can show me that VB.NET (or any modern high-level language, for that matter) won't ensure that in almost all cases (ListBox1.Items.Count-1) is precalculated and placed in a register when compiled into machine code, I'll show you a programming language that needs a serious rewrite. Another thing that compilers like to optimise for is the ability to test against 0, which often uses less code and is several cycles faster in many cases than tests against non-0 values. While most compilers will quite happily refactor a (0 to (count-1)) loop to take advantage of the faster test, a (1 to count) loop may force the compiler to use more/slower code in order to preserve the indexing, thereby wasting cycles. While this may not be true all of the time (and probably not so much now as it was when I first started coding), the point is that 0-based indexing can often provide a hint to the compiler to use a faster increment/decrement strategy. I think it's obvious now which camp I stand in. I think of it like this: if everything started at 1, then I would be a year older than I really am, and I'm old enough as it is. Bsides, when I was born I would have been 1 year old by default, which is clearly wrong no matter how bad you are at mathematics. In life as well as code, one must always start from 0 and work up from there. :-D

    "All programming is an exercise in caching." - Michael Abrash, GPBB

    The Lounge question php database design help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups