Jump to content

Multiple commands in a line (one liners)


ZeeXEez
 Share

Recommended Posts

Having multiple statements on one line can make it a nightmare to debug. I even avoid using nested function calls in unless the logic is simple and tried and tested for the following reasons:

1) If there is a problem and you need to debug it you have to un-nest it anyway to be able to see what the individual function calls return.

2) It makes it difficult to read and understand the flow of the code.

3) It does not make any difference to the speed of the code.

An exception to this is a scripting language that I use with a GIS application which is designed to put as much as possible on a single line.

This is an example of a single line from that.

{feature='Rail Network Link'}={feature='Rail Network Link' where {targ}.'FID'!='FID'}.({all intersect}.(if((!bitand(getintertype(), _INTERSECT_AEND) and !bitand(getintertype(), _INTERSECT_ASTART)),createfreem("88888",Xinterm(0),Yinterm(0),addattr('ERROR_CODE',str(zxprgrp)),addattr('FOUND_BY_PROCESS',"STRUXPR"),addattr('ERROR_FOUND_DATE',zsmdate),addattr('FREE_TEXT',str({targ}.FID,16,0)+" - Intersects "+str('FID',16,0)+" other than at a node"),addattr('SEVERITY',1),addattr('IEC',zxprnum),addattr('ERR_TILE',Getostilenamem(Xinterm(0),Yinterm(0),2500)),addattr('SQNAME',""),addattr('ERR_OCURANCES',1)),0)));

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Having multiple statements on one line can make it a nightmare to debug.

That's true. If you want to be able to easily debug your code visually than you wouldn't use one liners.

Ideal programming language doesn't have limitations. That language allows programmer to write everything in one line if one chooses to, it doesn't require $ for variables, etc, etc... It's up to programmer to set limits, not language.

Don't you agree?

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

That's true. If you want to be able to easily debug your code visually than you wouldn't use one liners.

Ideal programming language doesn't have limitations. That language allows programmer to write everything in one line if one chooses to, it doesn't require $ for variables, etc, etc... It's up to programmer to set limits, not language.

Don't you agree?

I don't agree. Languages should encourage simple and easy to read code. Python (which I'm currently writing an RD-parser in btw) is a great example of this:

"There should be one - and preferably only one - obvious way to do it." - http://www.python.org/dev/peps/pep-0020/

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

I don't agree. Languages should encourage simple and easy to read code. Python (which I'm currently writing a RD-parser in btw) is a great example of this:

"There should be one - and preferably only one - obvious way to do it." - http://www.python.org/dev/peps/pep-0020/

Encouraging something by not allowing something else is nazi. And gay.

I agree with you BTW. But since you don't agree with me, you're gay too.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

That's true. If you want to be able to easily debug your code visually than you wouldn't use one liners.

Ideal programming language doesn't have limitations. That language allows programmer to write everything in one line if one chooses to, it doesn't require $ for variables, etc, etc... It's up to programmer to set limits, not language.

Don't you agree?

If working with a language that has a good debugger that allows you to see the state of all variables and function return values then may comments about making debugging difficult are mostly invalid.

As for an Ideal programming language not imposing limits on the programmer, I'm not so sure that I would totally agree with that. I would allow very talented programmers to achieve exactly what they wanted by allowing their thoughts on how to solve a particular problem to be translated directly into code without the normal process of converting those thoughts into structure that a particular programming language requires. On the other hand I think such a language would be a nightmare in an environment where more than one programmer had to understand an maintain the code. Having a language that does impose some structures and limits does make it easier for others to understand especially those with less experience. I suppose that the compromise in an organization with multiple programmers would be a language that does not impose limitations, with a strong programming style guide that allowed the stye guide to be departed from where there was a very good reason.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

What ideal programming language allows you to write code in whatever way you want?

C variants have that stupid "{" after practically every line to tell the equally stupid compiler that you've gotten to the end of a command or loop or function or whatever they decide that character does next. The only way you're able to stuff everything onto one line is because of that bracket, so even without the $, there's still limitations. C variants, and other languages have case sensitive variable naming, which limits you on how you write your code because you have to remember the case of the variable names or you get an error and it won't compile. I could go on but why bother?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

What ideal programming language allows you to write code in whatever way you want?

C variants have that stupid "{" after practically every line to tell the equally stupid compiler that you've gotten to the end of a command or loop or function or whatever they decide that character does next. The only way you're able to stuff everything onto one line is because of that bracket, so even without the $, there's still limitations. C variants, and other languages have case sensitive variable naming, which limits you on how you write your code because you have to remember the case of the variable names or you get an error and it won't compile. I could go on but why bother?

Are you really complaining about case sensitivity? What about those capital letters at the beginning of your sentences? Or your name? Or abbreviations? Or any other place where capitalization is important.
Link to comment
Share on other sites

C variants, and other languages have case sensitive variable naming, which limits you on how you write your code because you have to remember the case of the variable names or you get an error and it won't compile. I could go on but why bother?

I just have to add that case sensitivity is a great feature. It allows you to write code like this:

class Person:
  pass

person = Person()

In case insensitive languages (like AutoIt3 or Delphi) you have to either prefix your variable (gross!) or use something else (like 'p' in this case) which may be unreadable and ambiguous.

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Are you really complaining about case sensitivity? What about those capital letters at the beginning of your sentences? Or your name? Or abbreviations? Or any other place where capitalization is important.

if i were to write this without any capitalization whatsoever, you'll still be able to understand what words i'm using. "modern" programming languages don't understand that dog and Dog are referencing the same thing because in programming, dog doesn't equal Dog.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

if i were to write this without any capitalization whatsoever, you'll still be able to understand what words i'm using. "modern" programming languages don't understand that dog and Dog are referencing the same thing because in programming, dog doesn't equal Dog.

That's because he knows English. He also knows C Sharp and he knows that in that language dog isn't the same as Dog per se.

Different languages, different rules.

Your second sentence should have been: "modern programming languages understand that dog and Dog don't reference the same thing because in programming, dog doesn't equal Dog". Then it would have made (some) sense.

If one language borrows words from another, it doesn't mean it should also borrow syntax or grammar.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

You obviously missed the part where he was referencing the words I wrote, in the English language, that also has capitalization rules but can be ignored and still be legible. I was replying to the question asked as I have no agenda, just a confusion as to why variables have to be case sensitive.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

What ideal programming language allows you to write code in whatever way you want?

As far as I now it does not exist yet. But it might be something like this.

I want the user to select their expenses file for the current month and when the user has selected the correct file I want to convert all the values in US dollars to British pounds and then save the file.

This would result in a fully functional application with GUIs or whatever other method was thought appropriate to get the required information from the user. Pie in the sky for now but in perhaps 10 years I think it will be possible to produce simple basic applications like this or even by just speaking to a computer and telling it what you want?

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

As far as I now it does not exist yet. But it might be something like this.

I want the user to select their expenses file for the current month and when the user has selected the correct file I want to convert all the values in US dollars to British pounds and then save the file.

This would result in a fully functional application with GUIs or whatever other method was thought appropriate to get the required information from the user. Pie in the sky for now but in perhaps 10 years I think it will be possible to produce simple basic applications like this or even by just speaking to a computer and telling it what you want?

There are some that try that in the GHS forum.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

You obviously missed the part where he was referencing the words I wrote, in the English language, that also has capitalization rules but can be ignored and still be legible. I was replying to the question asked as I have no agenda, just a confusion as to why variables have to be case sensitive.

Your example earlier was not quite right. Sure I understood what you intended, but what you wrote was wrong under a set of rules. In case sensitive languages, you can use both upper and lower case versions of a name and it can be understood but not valid.
Link to comment
Share on other sites

Well, you could confuse Bob with bob without context. a Marine with marine without the proper capitalization. Fortunately, context in human communication usually fixes the confusion in most cases

http://en.wikipedia.org/wiki/List_of_case-sensitive_English_words#List_of_capitonyms_in_English

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The all important thing, is do we really need this feature in AutoIt?

It's just more work for someone, and means less time spent on something else, no doubt more profitable ... unless there is a clear value and thus point to it?

Sometimes, I think we try too hard to make AutoIt be something else, when most of us love it and have stuck with it for so long, because of what it is .... and not how much it can be like another language ... seems some forget that, in their quest for ever bigger and better things or more power and flexibility.

It's a bit like marrying my wife despite and because of her flaws. She wouldn't be the same, and no doubt hold the same attraction without them .... in fact she'd be another person altogether. That doesn't mean she shouldn't strive to be the best she can, just that she should do it in context of who she is .... just like me and my context.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

It's a bit like marrying my wife despite and because of her flaws. She wouldn't be the same, and no doubt hold the same attraction without them .... in fact she'd be another person altogether. That doesn't mean she shouldn't strive to be the best she can, just that she should do it in context of who she is .... just like me and my context.

No it's nothing like that. Not bit, nothing.

...Heloo!!! Programming? Familiar with? Eh, I like you, but sometimes you really say dumb things.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

No it's nothing like that. Not bit, nothing.

...Heloo!!! Programming? Familiar with? Eh, I like you, but sometimes you really say dumb things.

I like you too, but you need to look deeper ... beyond the misunderstandings of words.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...