Page 2 of 2 FirstFirst 12
Results 41 to 54 of 54

Thread: Do you use ()'s for your IF statements?

  1. #41
    Lively Member
    Join Date
    Sep 2009
    Location
    Florida
    Posts
    75

    Re: Do you use ()'s for your IF statements?

    Quote Originally Posted by RipVoidWinkle View Post
    Good to know I am officially a dinosaur!

    I prefer writing code that is verbose and more readable, so I always leave the "= True"

    I think I prefer the ()'s as well, especially for compound conditions

    I never liked the += since I always mix it up with =+ and I just stay explicit and readable.
    I would use x++, if it is supported
    I'm also a dinosaur (started my programming career in 1965) and I agree with you.

    In general, a program is not just written then forgotten. In the commercial world, the ability to quickly and correctly maintain (modify or correct) code is of primary importance, whatever the language. The more clearly it is written and the better documented with comments, the easier it is to read, understand and modify ... regardless of the language.

    Just because it's not required doesn't mean it needs to be left out.
    "The most important quality a programmer must have is persistence."

  2. #42
    Lively Member
    Join Date
    Sep 2009
    Location
    Florida
    Posts
    75

    Re: Do you use ()'s for your IF statements?

    Quote Originally Posted by dday9 View Post
    I personally use the parenthesis around my If statements, even if it is just a single check. Mostly out of habit, not for any specific reason.

    Side note: COBOL is very verbose, but not very readable.
    I disagree with you about COBOL, having written and maintained hundreds of programs throughout the years (1970-2004) as a contractor for many Fortune 500 companies. (Just my 2 cents).
    "The most important quality a programmer must have is persistence."

  3. #43
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Do you use ()'s for your IF statements?

    Quote Originally Posted by wqweto View Post
    Wait. It is not possible to parse C or C# code with semicolons omitted. This means the IDE cannot disambiguate the intend of the code at all times and cannot automatically insert statement terminators too.

    Same for parens.
    Show me an example of C# code that can't be parsed using the same rules used by VB when the underscore was abandoned.

    @Wes: Some parentheses are necessary, enclosing the Boolean expression in C conditionals in parentheses is necessary because the compiler enforces it, not because the compiler can't understand the code without it.
    My usual boring signature: Nothing

  4. #44
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Do you use ()'s for your IF statements?

    @Niya: Everyone will have a preference, but the last time somebody showed an example of how concise C# could be over VB, they chose an unfortunate example which, while not trivial, required the same number of characters as the equivalent VB. There are just a bunch of extra stuff in C# which add up. When you add in intellisense shortcuts, VB probably requires less actual typing, and it is FAR easier typing, because symbols are two rows above the home row, and off on the periphery of the keyboard, for a reason.
    My usual boring signature: Nothing

  5. #45
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Do you use ()'s for your IF statements?

    Going off topic a bit, but if you guys want to see something wild check out APL. I helped somebody work through a problem with APL using Codejock controls. Believe it or not, there are modern version of APL that have COM support! Anyway, it was the first time I ever encountered a language that needed its own special keyboard Fun stuff though!

  6. #46
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Do you use ()'s for your IF statements?

    Quote Originally Posted by Shaggy Hiker View Post
    Show me an example of C# code that can't be parsed using the same rules used by VB when the underscore was abandoned.

    @Wes: Some parentheses are necessary, enclosing the Boolean expression in C conditionals in parentheses is necessary because the compiler enforces it, not because the compiler can't understand the code without it.
    I thought that's what you meant but I never pass up an opportunity to act confused.

  7. #47
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Do you use ()'s for your IF statements?

    Quote Originally Posted by Shaggy Hiker View Post
    @Niya: Everyone will have a preference, but the last time somebody showed an example of how concise C# could be over VB, they chose an unfortunate example which, while not trivial, required the same number of characters as the equivalent VB. There are just a bunch of extra stuff in C# which add up. When you add in intellisense shortcuts, VB probably requires less actual typing, and it is FAR easier typing, because symbols are two rows above the home row, and off on the periphery of the keyboard, for a reason.
    Don't get me wrong. You are correct in the fact that C# does have a lot of historical baggage from C that seem unnecessary and can make the language quite ugly and unrefined. Believe me, I've seen some ugly looking C# code. But trust me, when someone takes their time to refine C# code, it can be quite beautiful. I'm sorry I can't produce some examples off-hand but I sometimes I like to take a few hours and just go through random source code on GitHub, and I can tell you, I often find I prefer going through C# code a lot more than VB code. Believe me, it surprised the hell out of me since I am primarily a VB programmer. It might be fun for me to write but it sure as hell isn't as fun to read, especially when it's not my code.

    I don't really think it's that much the fault of the language. It's just that BASIC based languages tend to not lend themselves to formatting very well. There are thousands of sites out there with code samples and everyone uses their own style. Some use small fonts, some use large fonts, some use bolded fonts. Some people layout their code in tiny scroll boxes with syntax colouring, some without the syntax colouring. Some people use proper indentation, some don't. It's the wild west out there and I've found that C style languages lend themselves better too all these wild and crazy layouts better than BASIC code. A very common example I run into is code boxes that word wrap. Sometimes I run into a blog or forum post that will have some form of BASIC code in a tiny box with a bolded fonts and you end up trying to parse a single line that's been wrapped to several lines while the spacing gets all mangled. It's very very difficult to read, it's extremely annoying and it's mainly because BASIC is just so wordy. I don't see this very often with C style code at all. The C syntax fits perfectly with a variety of layouts and I suspect this is one of the main reasons it's such a popular syntax because I've heard other bring up this very point before about BASIC being hard to read and too verbose.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  8. #48
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Do you use ()'s for your IF statements?

    Quote Originally Posted by Shaggy Hiker View Post
    Show me an example of C# code that can't be parsed using the same rules used by VB when the underscore was abandoned.
    Not aware of these rules but C/C++/C# code as is with ";" replaced with " " can become ambiguous very fast.

    VB's implicit lines continuation rules depend on the language syntax and are not applicable to C-kind of languages IMO.

    cheers,
    </wqw>

  9. #49
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Do you use ()'s for your IF statements?

    But you do know the VB line continuation character. It was convenient, because it meant that a line ended at the end of the line. When lambdas were added with FW 3.5, the end of the line became ambiguous. A multi-line lambda was kind of one line, kind of many lines, so figuring out whether the line continuation was necessary or not could get ambiguous. Therefore, they just let the compiler figure it out, and it does. The same could have been done in C#...with a caveat.

    The caveat is that, because of the semicolon, it may be possible to write some monstrosities where there are multiple lines on a single line, and the compiler may not be able to work out what is happening there....though, I'm not sure that's the case, either. The more I think about it, the more I think that it should be possible to parse darn near anything. So, I'm not even sure if the caveat is real.
    My usual boring signature: Nothing

  10. #50
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Do you use ()'s for your IF statements?

    Quote Originally Posted by Shaggy Hiker View Post
    So, I'm not even sure if the caveat is real.
    Optional semicolons have already been discussed: https://github.com/dotnet/csharplang/issues/1581

    The general opinion is that the C# syntax is rife with ambiguities and the proposition cannot be accepted as is.

    cheers,
    </wqw>

  11. #51
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Do you use ()'s for your IF statements?

    I was considering whether semicolons are necessary in JavaScript. I kind of think that they are because JS can be minified. I don't believe you can minify code without semicolons, but for a compiled language, they're an anachronism. Now, there may be some code out there that took a bit too many advantages of that, which is unfortunate, but the change could still happen. There was plenty of code that was broken by ANSI C++, as well, and we got through that with tolerable pain.
    My usual boring signature: Nothing

  12. #52
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    557

    Re: Do you use ()'s for your IF statements?

    Removing all ugly brackets (except where required), semicolons, change syntax here and there and what we get? Another language. That is what happens all the time. It is no more C# (or whatever other language is changed).

    VB.NET and C# are not just languages. They are part of ecosystem - from the thousands of objects in the framework to supported OS platforms, different user interface possibilities (WinForms, WPF, Xamarin, UWP, webforms, MVC, SPA, Blazor), web oriented solutions (apps, services, clients), third party libraries (NuGet), various tooling (builds, tests, deployment), great IDE with powerful debugger and others I can't remember now.

    There were added many new language features as the features were added to the whole ecosystem. Lambdas, threads, tasks, async, attributes, anonymous objects, dynamic objects... Well, C# evolution has bigger progress as it was chosen to be the core language in Microsoft so everything new is added to C# to improve code development, maintenance, performance.

    Developers should evolve with the language. It is everyday learning, as new techs are coming everyday. Sometimes sticking to single platform is mistake (as sticking to single language). When I read about verbosity of VB, I remember when I saw for first time how web service is created in Node.js or Go and compared that to ASP.NET web services. What "verbosity" of all the setup and configuration for the service to startup. The same can be said for JavaScript (even using Electron) or other language based desktop UI app which in VB6 or in VB.NET (or C#) is drag and drop few controls and double click on button and start creating business value in less than minute.

    Also the design of application (not UI) can be very annoying for people who never dealt with something more complex. But sometimes the software design makes things much easier when you add more features to the app and more people or teams are working on these features. Many questions in this subforum are about DataGridView, data tables and data binding and that repeats so often so I really hated these. For simple data access (read/write from/to SQL database) I have to create several solutions and project directories for shared data models, readers and writers interfaces for the data, implementation of readers and writers for the specific SQL database server (MSSQL, MySQL, SQLite, ...). There is also other logic and sometimes another layer of complexity with commands and events (when using CQRS and ES), registering and handling of these commands and events. Which most people will just write in the "form" as simple SQL statements for select, insert, update and delete.

    To be back to language improvements and changes. Few months ago VS2019 suggests to remove ByVal in method parameters declaration. Well, I know that the default in VB.NET is ByVal but these suggestions are annoying me (even they can be turned off) as at least the methods declarations I am keeping compatible with VB6 where parameter is assumed ByRef if ByVal is omitted. And sometimes I have to use .NET COM objects from VB6 and having the proper declaration is simple copy and paste. I know it is not an issue but its just me being annoyed.

    To finish my post, as I already wrote about coding style and sticking to it, there are few rules which can be applied to most languages. Most important is to keep procedures (methods, functions) length to fit in 30-35 lines of source code including comments and white space (Linux kernel source code rules were max 30 lines IIRC). My actual code window size is reduced to fit 40-42 lines so it is natural rule to keep everything short. In rare cases longer procedures are left but they are containing switch/select case statements. If something becomes longer then it must be refactored. The procedure must be short enough to be read in a glance and the developer to understand what it does quickly instead of started thinking what happens.

  13. #53
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Do you use ()'s for your IF statements?

    We've wandered far from () in If statements, but it all seems pretty good.
    My usual boring signature: Nothing

  14. #54
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    557

    Re: Do you use ()'s for your IF statements?

    We started from brackets and reached C#, semicolons and landed in Rust world in VB.NET talk. For those who are interested in languages evolution, there is the link to Kotlin language in Wikipedia, where something related to this talk is written:

    Design
    ...
    Development lead Andrey Breslav has said that Kotlin is designed to be an industrial-strength object-oriented language, and a "better language" than Java, but still be fully interoperable with Java code, allowing companies to make a gradual migration from Java to Kotlin.

    Semicolons are optional as a statement terminator; in most cases a newline is sufficient for the compiler to deduce that the statement has ended.

    Kotlin variable declarations and parameter lists have the data type come after the variable name (and with a colon separator), similar to BASIC, Pascal and TypeScript.

    Variables in Kotlin can be read-only, declared with the val keyword, or mutable, declared with the var keyword.
    ...

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width