www.digitalmars.com         C & C++   DMDScript  

D - with/struct

reply "Carlos Santander B." <carlos8294 msn.com> writes:
Hi, can someone please explain to me the reasoning behind not allowing with
() for structs?

-------------------------
Carlos Santander


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25
Mar 27 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Carlos Santander B." <carlos8294 msn.com> wrote in message
news:b5vi3m$25un$1 digitaldaemon.com...
 Hi, can someone please explain to me the reasoning behind not allowing
with
 () for structs?
Oversight? :-)
Mar 27 2003
parent reply Carlos Santander B. <Carlos_member pathlink.com> writes:
In article <b5vmge$2a17$3 digitaldaemon.com>, Walter says...
"Carlos Santander B." <carlos8294 msn.com> wrote in message
news:b5vi3m$25un$1 digitaldaemon.com...
 Hi, can someone please explain to me the reasoning behind not allowing
with
 () for structs?
Oversight? :-)
Walter, what has happened with this? Still doesn't work... ------------------- Carlos Santander B.
Mar 11 2004
parent reply Ant <duitoolkit yahoo.ca> writes:
On Thu, 11 Mar 2004 16:54:50 +0000, Carlos Santander B. wrote:

 In article <b5vmge$2a17$3 digitaldaemon.com>, Walter says...
"Carlos Santander B." <carlos8294 msn.com> wrote in message
news:b5vi3m$25un$1 digitaldaemon.com...
 Hi, can someone please explain to me the reasoning behind not allowing
with
 () for structs?
Oversight? :-)
Walter, what has happened with this? Still doesn't work... ------------------- Carlos Santander B.
If you ask me 'with' is up there with 'goto' and 'break' and 'continue'. 'with' is an invitation to coders to expose details that should be hidden somewhere else :p Ant
Mar 11 2004
next sibling parent reply Ilya Minkov <minkov cs.tum.edu> writes:
I don't think i can follow. I come from Delphi where i came to like it. 
It is mostly a notational shortcut.

-eye

Ant schrieb:
 If you ask me 'with' is up there
 with 'goto' and 'break' and 'continue'.
 
 'with' is an invitation to coders to expose
 details that should be hidden somewhere else :p
 
 Ant
 
Mar 11 2004
parent Ant <duitoolkit yahoo.ca> writes:
On Fri, 12 Mar 2004 00:33:49 +0100, Ilya Minkov wrote:

 I don't think i can follow. I come from Delphi where i came to like
 it [with]. 
 It is mostly a notational shortcut.
 
 -eye
nobody is perfect ;) Ant
Mar 11 2004
prev sibling next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
Ant wrote:
 On Thu, 11 Mar 2004 16:54:50 +0000, Carlos Santander B. wrote:
 
 
In article <b5vmge$2a17$3 digitaldaemon.com>, Walter says...

"Carlos Santander B." <carlos8294 msn.com> wrote in message
news:b5vi3m$25un$1 digitaldaemon.com...

Hi, can someone please explain to me the reasoning behind not allowing
with
() for structs?
Oversight? :-)
Walter, what has happened with this? Still doesn't work... ------------------- Carlos Santander B.
If you ask me 'with' is up there with 'goto' and 'break' and 'continue'. 'with' is an invitation to coders to expose details that should be hidden somewhere else :p Ant
I like "with". I go out of my way to use it. I'd use it for structs, too, if the compiler allowed it. I don't like "goto" (I prefer my spaghetti on a dinner plate), either. I have to use "break" on all of my switch constructs because I rarely fall-through. I don't think I've ever used "continue". What's it for? :) -- Justin http://jcc_7.tripod.com/d/
Mar 11 2004
next sibling parent Ant <duitoolkit yahoo.ca> writes:
On Thu, 11 Mar 2004 17:47:48 -0600, J C Calvarese wrote:

 Ant wrote:
 
 If you ask me 'with' is up there
 with 'goto' and 'break' and 'continue'.
 
 'with' is an invitation to coders to expose
 details that should be hidden somewhere else :p
 
 Ant
 
I like "with". I go out of my way to use it. I'd use it for structs, too, if the compiler allowed it. I don't like "goto" (I prefer my spaghetti on a dinner plate), either. I have to use "break" on all of my switch constructs because I rarely fall-through.
That 'break' is different.
 
 I don't think I've ever used "continue". What's it for? :)
As I remember on looks skips the rest of the current iteraction. Ant
Mar 11 2004
prev sibling parent reply =?ISO-8859-1?Q?Sigbj=F8rn_Lund_Olsen?= <sigbjorn lundolsen.net> writes:
 I like "with". I go out of my way to use it. I'd use it for structs, 
 too, if the compiler allowed it.
Never used with. What's it for?
 I don't like "goto" (I prefer my spaghetti on a dinner plate), either.
Goto gives me nightmares.
 I have to use "break" on all of my switch constructs because I rarely 
 fall-through.
Me too.
 I don't think I've ever used "continue". What's it for? :)
Breaking a loop iteration execution, instead of breaking the loop execution. Very handy. Cheers, Sigbjørn Lund Olsen
Mar 12 2004
parent J C Calvarese <jcc7 cox.net> writes:
Sigbjørn Lund Olsen wrote:
 
 I like "with". I go out of my way to use it. I'd use it for structs, 
 too, if the compiler allowed it.
Never used with. What's it for?
It facilitates referring to the same object repeatedly. I'll quote another's work to make my point: [Without "with"] fileSelector = new Button (this) fileSelector.caption ("&File Selector"); fileSelector.onClick.add (&fileSelectorClick); fileSelector.alignLeft (true); fileSelector.gridAddRow (0, r); fileSelector.sticky ("<>^"); [With "with"] with (fileSelector = new Button (this)) { caption ("&File Selector"); onClick.add (&fileSelectorClick); alignLeft (true); gridAddRow (0, r); sticky ("<>^"); } That explains it for me... [...]
 Cheers,
 Sigbjørn Lund Olsen
-- Justin http://jcc_7.tripod.com/d/
Mar 12 2004
prev sibling next sibling parent reply Andy Friesen <andy ikagames.com> writes:
Ant wrote:
 If you ask me 'with' is up there
 with 'goto' and 'break' and 'continue'.
 
 'with' is an invitation to coders to expose
 details that should be hidden somewhere else :p
There's a case to be made that the with() construct reduces errors as well, as the program isn't typing the same identifier over and over again. It also makes code easier to read. with() can certainly be misused, but so can switch: switch (x) { while (x) { printf("%i\n", x); x++; continue; case 0: x = 1337; continue; case 1: x = -1; continue; } } -- andy
Mar 11 2004
parent reply Ant <duitoolkit yahoo.ca> writes:
On Thu, 11 Mar 2004 17:29:54 -0800, Andy Friesen wrote:

 Ant wrote:
 If you ask me 'with' is up there
 with 'goto' and 'break' and 'continue'.
 
 'with' is an invitation to coders to expose
 details that should be hidden somewhere else :p
There's a case to be made that the with() construct reduces errors as well, as the program isn't typing the same identifier over and over again.
but that's my point, if your are typing the same identifier over and over you should review something. (you have to forgive me all these rants come from years of working with code of inferior quality and I can assure you: no 'break', 'goto', 'continue' or 'with' are necessary to produce bad code:( )
 It also makes code easier to read.
 
 with() can certainly be misused, but so can switch:
 
     switch (x) {
        while (x) {
           printf("%i\n", x);
 
           x++;
           continue;
 
        case 0: x = 1337; continue;
        case 1: x = -1; continue;
        }
     }
 
   -- andy
Someone showed before that you could have a statment inside a switch but outside a case! (did you compile that?) is that common to other languages? I don't remember seeing it and certanly I don't intend to use it. Ant
Mar 11 2004
next sibling parent Juan C <Juan_member pathlink.com> writes:
I've never used with. Most of the time I kinda wanted to use with I was copying
items from one structure to another, but with only works with one structure at a
time. So I'd still have to type out one of them while using with on the other,
and that seems like poor (inconsistent) style.

If anyone can come up with a with that can be used on several structures at a
time then I might use it, but probably not, so don't bother.

As to continue and break... I try not to use them, except for break in switches.
Most of the times I've used continue it's after a text file read; if the line is
empty, just continue.
Mar 11 2004
prev sibling next sibling parent reply Andy Friesen <andy ikagames.com> writes:
Ant wrote:
There's a case to be made that the with() construct reduces errors as 
well, as the program isn't typing the same identifier over and over 
again.
but that's my point, if your are typing the same identifier over and over you should review something.
Sounds like a bit of an overgeneralization. :) (from Burton Raydons's Dig library example, halhello.d) with (fileSelector = new Button (this)) { caption ("&File Selector"); onClick.add (&fileSelectorClick); alignLeft (true); gridAddRow (0, r); sticky ("<>^"); } Is this really so horrible?
with() can certainly be misused, but so can switch:

    switch (x) {
       while (x) {
          printf("%i\n", x);

          x++;
          continue;

       case 0: x = 1337; continue;
       case 1: x = -1; continue;
       }
    }
Someone showed before that you could have a statment inside a switch but outside a case! (did you compile that?)
It's valid D, C, and C++. (according to gcc 3.3.1, anyhow)
 is that common to other languages?
 I don't remember seeing it and certanly I don't intend to
 use it.
The point is that anything can be abused if you look hard enough. with() is no exception, but it's hardly as dangerous as goto. -- andy
Mar 11 2004
parent reply Ant <duitoolkit yahoo.ca> writes:
On Thu, 11 Mar 2004 20:08:18 -0800, Andy Friesen wrote:

 Ant wrote:
There's a case to be made that the with() construct reduces errors as 
well, as the program isn't typing the same identifier over and over 
again.
but that's my point, if your are typing the same identifier over and over you should review something.
Sounds like a bit of an overgeneralization. :)
Of course it is, I'm sorry.
 
 (from Burton Raydons's Dig library example, halhello.d)
 
          with (fileSelector = new Button (this))
          {
              caption ("&File Selector");
              onClick.add (&fileSelectorClick);
              alignLeft (true);
              gridAddRow (0, r);
              sticky ("<>^");
          }
 
 Is this really so horrible?
 
Yes! Nothing makes sence on those few lines... that's why I started DUI instead of looking into a linux version of dig. I just tool a look at the halhello.d I bet there where no nested functions whe he wrote that. (but it's a shame we lost Burton. He left about the time I came abord. On the DLab group Burton said he was preparing a post with a critique of D (or something like that)) Ant of course this is my opinion.
Mar 11 2004
parent reply Ilya Minkov <minkov cs.tum.edu> writes:
Ant schrieb:

(from Burton Raydons's Dig library example, halhello.d)

         with (fileSelector = new Button (this))
         {
             caption ("&File Selector");
             onClick.add (&fileSelectorClick);
             alignLeft (true);
             gridAddRow (0, r);
             sticky ("<>^");
         }

Is this really so horrible?
Yes! Nothing makes sence on those few lines... that's why I started DUI instead of looking into a linux version of dig. I just tool a look at the halhello.d I bet there where no nested functions whe he wrote that.
Again, why? I think it's beautyful. And how would you like to do it (better) without with? Just removing with doesn't make it any better you know, instead it looses structure!
 (but it's a shame we lost Burton. He left
 about the time I came abord.
 On the DLab group Burton said he was preparing
 a post with a critique of D (or something like that))
He's been popping up a few times, esp. when new compiler versions come out, just to say that dig doesn't work. :> Probably he feels somewhat disappointed by something along these lines. Now that his own compiler is too much out-of-date. -eye
Mar 12 2004
next sibling parent reply Ant <duitoolkit yahoo.ca> writes:
On Fri, 12 Mar 2004 20:54:13 +0100, Ilya Minkov wrote:

 Ant schrieb:
 
(from Burton Raydons's Dig library example, halhello.d)

         with (fileSelector = new Button (this))
         {
             caption ("&File Selector");
             onClick.add (&fileSelectorClick);
             alignLeft (true);
             gridAddRow (0, r);
             sticky ("<>^");
         }

Is this really so horrible?
Yes! Nothing makes sence on those few lines... that's why I started DUI instead of looking into a linux version of dig. I just tool a look at the halhello.d I bet there where no nested functions whe he wrote that.
Again, why? I think it's beautyful. And how would you like to do it (better) without with? Just removing with doesn't make it any better you know, instead it looses structure!
 (but it's a shame we lost Burton. He left
 about the time I came abord.
 On the DLab group Burton said he was preparing
 a post with a critique of D (or something like that))
He's been popping up a few times, esp. when new compiler versions come out, just to say that dig doesn't work. :> Probably he feels somewhat disappointed by something along these lines. Now that his own compiler is too much out-of-date. -eye
just create a nested function to do a similar job, then it can be used to all the 3 buttons on that halhello prog method. or just extend the Button class the create buttons that don't use the usual Button (this example doesn't justitfy that). but the entire thing is wrong should be on the lines of: fileSelector = new Button(this, "&File Selector", &fileSelectorClick); fileSelector.align(Align.EAST); fileSelector.sticky(0.0, 1.0, 0.0, 0.0); grid.add(fileSelector, 0, r); - the ctor should accept the very common parameters for convinience. - alingLeft(), alignRight(), alignTop(), alignBottom(), alignLeftTop()...? - sticky(char[]) is just a bad idea - seems unnatural that the button adds it self to some container. Ant Once I was wrong!!! I thought I had maid a mistake but I didn't. (my boss told me that one) So I could be wrong again.
Mar 12 2004
parent Ant <duitoolkit yahoo.ca> writes:
Well, the conclusion is,

nothing good come out of this discussion.
Nobody agrees with me and you guys
now put me closer to the radial idiot mark :)

I guess I sound much smarter if I keep my
mounth close ;)

it's also interesting that nobody complains
on dig's API. It's so strange! probably it's
a windows thing and I'm just not used to it.

Ant
Mar 12 2004
prev sibling parent J C Calvarese <jcc7 cox.net> writes:
Ilya Minkov wrote:
 Ant schrieb:
 (from Burton Raydons's Dig library example, halhello.d)
[...]
 (but it's a shame we lost Burton. He left
 about the time I came abord.
 On the DLab group Burton said he was preparing
 a post with a critique of D (or something like that))
He's been popping up a few times, esp. when new compiler versions come out, just to say that dig doesn't work. :> Probably he feels somewhat disappointed by something along these lines. Now that his own compiler is too much out-of-date.
It sounds like he want to use D to create another language. Part of his plans is some fancy template thing that either reveals a bug in the compiler or a feature that Walter hasn't implemented. Parts of dig (the header stripper, for example) may not work right now, but I think it's mostly been updated. Burton may have lost interest in D, but dig isn't necessarily down for the count. I hope he does post his issues with D, so that I can know what I need to work around. My issues with D are pretty insignificant, so I plan to stick around.
 
 -eye
-- Justin http://jcc_7.tripod.com/d/
Mar 12 2004
prev sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
Ant wrote:

On Thu, 11 Mar 2004 17:29:54 -0800, Andy Friesen wrote:

  

Ant wrote:
    

If you ask me 'with' is up there
with 'goto' and 'break' and 'continue'.

'with' is an invitation to coders to expose
details that should be hidden somewhere else :p
      
There's a case to be made that the with() construct reduces errors as well, as the program isn't typing the same identifier over and over again.
but that's my point, if your are typing the same identifier over and over you should review something. (you have to forgive me all these rants come from years of working with code of inferior quality and I can assure you: no 'break', 'goto', 'continue' or 'with' are necessary to produce bad code:( )
I like *with* because it makes changes to the code more easy. You only need to change the variable name in one place. For me at least it's also easier to read because there is less to read. -- -Anderson: http://badmama.com.au/~anderson/
Mar 11 2004
prev sibling parent reply "C. Sauls" <ibisbasenji yahoo.com> writes:
Hmm... in a world without with...

     BOOL success;
     WNDCLASSEX wincls;
     wincls.cbSize        = WNDCLASSEX.sizeof;
     wincls.style         = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
     wincls.lpfnWndProc   = &mainWinProc;
     wincls.cbClsExtra    = 0;
     wincls.cbWndExtra    = 0;
     wincls.hInstance     = _instance;
     wincls.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
     wincls.hCursor       = LoadCursor(NULL, IDC_ARROW);
     wincls.hbrBackground = cast(HBRUSH) GetStockObject(WHITE_BRUSH);
     wincls.lpszMenuName  = NULL;
     wincls.lpszClassName = "MyAppMainWC";
     wincls.hIconSm       = NULL;
     success              = RegisterClassEx(&wincls);

Meanwhile in this world, where we do have with (if only it worked on 
structs)...

     WNDCLASSEX wincls;
     with (wincls) {
         cbSize        = WNDCLASSEX.sizeof;
         style         = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
         lpfnWndProc   = &mainWinProc;
         cbClsExtra    = 0;
         cbWndExtra    = 0;
         hInstance     = _instance;
         hIcon         = LoadIcon(NULL, IDI_APPLICATION);
         hCursor       = LoadCursor(NULL, IDC_ARROW);
         hbrBackground = cast(HBRUSH) GetStockObject(WHITE_BRUSH);
         lpszMenuName  = NULL;
         lpszClassName = "MyAppMainWC";
         hIconSm       = NULL;
         success       = RegisterClassEx(this);
     }

I think I like it in this with-enabled world.  Besides, if I remember 
right with() only exposes the public members of an object anyhow, yes? 
How does that lead to bugs?

-C. Sauls
-Invironz

Ant wrote:
 On Thu, 11 Mar 2004 16:54:50 +0000, Carlos Santander B. wrote:
 
 
In article <b5vmge$2a17$3 digitaldaemon.com>, Walter says...

"Carlos Santander B." <carlos8294 msn.com> wrote in message
news:b5vi3m$25un$1 digitaldaemon.com...

Hi, can someone please explain to me the reasoning behind not allowing
with
() for structs?
Oversight? :-)
Walter, what has happened with this? Still doesn't work... ------------------- Carlos Santander B.
If you ask me 'with' is up there with 'goto' and 'break' and 'continue'. 'with' is an invitation to coders to expose details that should be hidden somewhere else :p Ant
Mar 12 2004
parent Ant <duitoolkit yahoo.ca> writes:
On Fri, 12 Mar 2004 05:10:27 -0600, C. Sauls wrote:

 I think I like it in this with-enabled world.
Seems that every body likes 'with'. So it must be a good thing :) thank you all for the examples. Ant
Mar 12 2004