New topic: Simpler Notation?
<http://forums.realsoftware.com/viewtopic.php?t=30735> Page 1 of 1 [ 6 posts ] Previous topic | Next topic Author Message JustSomeGuy Post subject: Simpler Notation?Posted: Thu Oct 29, 2009 12:19 pm Joined: Fri May 11, 2007 11:35 am Posts: 549 In C:Code:Fragment_Size = Left_To_Send > Max_Fragment_Size ? Max_Fragment_Size ? Left_To_SendIn RB: ? Code:if Left_To_Send > Max_Fragment_Size then Fragment_Size = Max_Fragment_Size else Fragment_Size = Left_To_Send end if Is there a simpler notation in RB? _________________ A picture paints a thousand words. A thought paints a thousand pictures. Top Bob Keeney Post subject: Re: Simpler Notation?Posted: Thu Oct 29, 2009 12:28 pm Joined: Fri Sep 30, 2005 11:48 am Posts: 1345 Location: Lenexa, KS Code:Fragment_Size = Max(Max_Fragment_Size, Left_To_Send) _________________ Bob K. The Association of REALbasic Professionals http://www.arbpmembers.org/ BKeeney Software Inc. - REALbasic Consulting http://www.bkeeney.com/ BKeeney Briefs Blog For REALbasic Developers http://www.bkeeneybriefs.com/ Top Indy Post subject: Re: Simpler Notation?Posted: Thu Oct 29, 2009 12:30 pm Joined: Wed Jul 09, 2008 10:46 pm Posts: 102 Location: Minneapolis Bob Keeney wrote:Code:Fragment_Size = Max(Max_Fragment_Size, Left_To_Send) Actually, I think you want MIN (not MAX) in this situation. _________________ http://www.miscjunk.org Top Steve Garman Post subject: Re: Simpler Notation?Posted: Thu Oct 29, 2009 12:34 pm Joined: Fri Sep 30, 2005 3:53 pm Posts: 3078 Location: England There is no Ternary operator in RB. Yo could shorten stuff with a function likeCode:Function iif(b As Boolean, t As Variant, f As Variant) As Variant If b Then Return t Else Return f End If End Function and useCode:Fragment_Size = iif(Left_To_Send > Max_Fragment_Size , Max_Fragment_Size , Left_To_Send) Edit: but as others have pointed out, Min or Max are better for this particular case. _________________ Steve Garman Using REALbasic 2008r2 Professional on Windows Vista Ultimate and REALbasic 2009r4 Professional on Linux Ubuntu 9.04 Desktop Occasional blog Last edited by Steve Garman on Thu Oct 29, 2009 12:36 pm, edited 1 time in total. Top jefftullin Post subject: Re: Simpler Notation?Posted: Thu Oct 29, 2009 12:36 pm Joined: Wed Nov 15, 2006 3:50 pm Posts: 890 depending upon why you want to simplify it, this version assumes max_fragment_size until proven wrong: Code: Dim Fragment_Size as integer = Max_Fragment_Size while Left_To_Send > Max_Fragment_Size Write (Fragment size) 'which I assume affects left_to_send wend Write (left_to_send) OT: I find it amusing that you think the C version is the simpler! Top Steve Garman Post subject: Re: Simpler Notation?Posted: Thu Oct 29, 2009 12:42 pm Joined: Fri Sep 30, 2005 3:53 pm Posts: 3078 Location: England jefftullin wrote:OT: I find it amusing that you think the C version is the simpler! When you are used to it, that sort of notation often makes complex code easier to read. But who am I to talk? I think Code:Bytes_To_Send ++is often clearer (and less error prone) than Code:Bytes_To_Send = Bytes_To_Send + 1 _________________ Steve Garman Using REALbasic 2008r2 Professional on Windows Vista Ultimate and REALbasic 2009r4 Professional on Linux Ubuntu 9.04 Desktop Occasional blog Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 6 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
