1. Coding conventions
- Posted by SDPringle Apr 05, 2009
- 1082 views
Code wrapping conventions: From the developers list, there was talk about wrapping. Now, if you wrap you have to set a specific line length. Suppose you don't set any line length at all? You're editor does the wrapping for you but sometimes the structure is not clear when you leave it to the editor. I have taken this here beause it is more suitable for illistration purposes.
Here is no wrapping:
-- lower for Windows or DOS, lower for all. K.I.S.S. sequence translator_base = lower(translator[search:rfind(SLASH,translator)+1..$]) sequence interpreter_base = lower(executable[search:rfind(SLASH,executable)+1..$]) integer dos_or_win = find(platform(),{WIN32,DOS32}) if (match( "eucd", translator_base ) != 0) or ( length(translator) = 0 and platform() = DOS32 ) then -- NOOP elsif (match( "ecw", translator_base ) != 0 and dos_or_win)or (match( "euc", translator_base ) != 0 and dos_or_win ) or ( length(translator) = 0 and platform() = WIN32 ) then translator_options &= " -CON" elsif ( match( "ecu", translator_base ) != 0 ) or ( match( upper("euc"), upper(translator) ) != 0 )or ( length(translator) = 0 and find( platform(), { LINUX, FREEBSD, OSX, SUNOS, OPENBSD } ) ) then -- NOOP elsif match( upper("ec.exe"), upper(translator) ) != 0 then -- NOOP else printf( 2, "Cannot determine translator\'s platform.", {} ) abort(1) end if
Here is wrapping at 132:
-- lower for Windows or DOS, lower for all. K.I.S.S. sequence translator_base = lower(translator[search:rfind(SLASH,translator)+1..$]) sequence interpreter_base = lower(executable[search:rfind(SLASH,executable)+1..$]) integer dos_or_win = find(platform(),{WIN32,DOS32}) if (match( "eucd", translator_base ) != 0) or ( length(translator) = 0 and platform() = DOS32 ) then -- NOOP elsif (match( "ecw", translator_base ) != 0 and dos_or_win)or (match( "euc", translator_base ) != 0 and dos_or_win ) or ( length(translator) = 0 and platform() = WIN32 ) then translator_options &= " -CON" elsif ( match( "ecu", translator_base ) != 0 ) or ( match( upper("euc"), upper(translator) ) != 0 ) or ( length(translator) = 0 and find( platform(), { LINUX, FREEBSD, OSX, SUNOS, OPENBSD } ) ) then -- NOOP elsif match( upper("ec.exe"), upper(translator) ) != 0 then -- NOOP else printf( 2, "Cannot determine translator\'s platform.", {} ) abort(1) end if
Here is wrapping at 80 (for console editors)
-- lower for Windows or DOS, lower for all. K.I.S.S. sequence translator_base = lower(translator[search:rfind(SLASH,translator)+1..$]) sequence interpreter_base = lower(executable[search:rfind(SLASH,executable)+1..$]) integer dos_or_win = find(platform(),{WIN32,DOS32}) if (match( "eucd", translator_base ) != 0) or ( length(translator) = 0 and platform() = DOS32 ) then -- NOOP elsif (match( "ecw", translator_base ) != 0 and dos_or_win) or (match( "euc", translator_base ) != 0 and dos_or_win ) or ( length(translator) = 0 and platform() = WIN32 ) then translator_options &= " -CON" elsif ( match( "ecu", translator_base ) != 0 ) or ( match( upper("euc"), upper(translator) ) != 0 ) or ( length(translator) = 0 and find( platform(), { LINUX, FREEBSD, OSX, SUNOS, OPENBSD } ) ) then -- NOOP elsif match( upper("ec.exe"), upper(translator) ) != 0 then -- NOOP else printf( 2, "Cannot determine translator\'s platform.", {} ) abort(1) end if
There is also the subject of what is the best indent size, given 80 line length, 8 is too big IMO.
Shawn Pringle
2. Re: Coding conventions
- Posted by jeremy (admin) Apr 05, 2009
- 1023 views
The official standard for code being contributed to Euphoria is lines must wrap by 100 characters. When you hit 90, start thinking of wrapping. Tab's should be used to indent and your tab size (indent size) is 4.
No editor I know of indents code correctly with auto wrap. Some try but fail in many situations. There may be some, but they are few and far between, therefore you should not count on someone else having the same luxury you do.
So, wrap by 100 max, start thinking about it at 90, indent with tabs, tab size of 4.
Jeremy
3. Re: Coding conventions
- Posted by jeremy (admin) Apr 05, 2009
- 1047 views
Oh, the word wrapping also goes for commit log messages as well. Too many tools (SVN log included) does not wrap words and things look pretty sloppy and harder to find information when browsing the log.
On that note, the SVN log entries should be bullet lists.
* Translator now accepts a -makefile flag which will create a <prgname>.mak file instead of an emake/emake.bat file. This file contains two variables called <PRGNAME>_SOURCES and <PRGNAME>_OBJECTS. This <prgname>.mak file can then be included in your larger project's Makefile. * Euphoria interpreter/translator/backend should be changed to use this new feature. * This completes feature request 2477562.
For instance. When viewing in a SVN log from the console, the above is very readable. When exporting our SVN log to Creole format, it's beautiful. When viewing by viewsvn or via the our cia.vc project page, the bullet list is properly formatted. Many other log viewers do the same thing with bullet lists.
Even if the item is just one line, it should be a bullet list:
* Fixed pipeio demo to not require stdin being closed.
Jeremy