code Review

Can you explain me about the following code? What it does?

&IF "{&WINDOW-SYSTEM}" = "TTY" &THEN
INPUT THROUGH uname -n.
IMPORT lcComputer.
INPUT CLOSE.
&SCOPED-DEFINE CommandSep CHR(47)
&ELSE
ASSIGN lcComputer = OS-GETENV("CLIENTNAME").
IF lcComputer = ? THEN lcComputer = OS-GETENV("COMPUTERNAME").
IF lcComputer EQ ? THEN lcComputer = "".
&SCOPED-DEFINE CommandSep CHR(92)
&ENDIF

Thanks & Regards
Sanjay
 
Sure,

This looks like an attempt to assign the name of the machine running the code to the variable lcComputer.

The use of the WINDOW-SYSTEM preprocessor means that the first section of code will be compiled in if the machine doing the compiling is a character windowing system (unix, for example). This will result in the use of the uname command to get the name of the host machine.

The second section will be compiled in for all other cases (MS-WINDOWS, MS-WIN95 etc), and so OS-GETENV is then used to check the system's enironment variabled for the host name.

You can also see here the selective definition of a CommandSep preprocessor. This attempts to pick a slash character to use based on the nature of the host windowing system. So, if you compile this code in unix, you will get a "/" character, and in windows a "\" character, which is probably used for file and directory pathnames later on.
 

TomBascom

Curmudgeon
Of course r-code is potentially portable across operating systems and it is also quite possible to be running in TTY mode on Windows so this code is grossly flawed and will fail in many scenarios.

These sorts of checks for OS type should be run time checks using the OPSYS function not compile time checks based on preprocessors like {&WINDOW-SYSTEM}.
 
Yeah, as Tom said this is pretty shonky code. It probably works in your environment because you compile in a similar environment to that which you intend to ship to. But better structure would result in truely portable code, removing the need to compile in different environments entirely.

I missed the point of the post - I read "what does this code do" and missed the topic of "code review". I'm normally the first to lay into bad code as well! What a missed opportunity! :biggrin:
 
Top