Re: svn commit: r329609 - head/stand/lua
Ian Lepore wrote: > On Mon, 2018-02-19 at 22:29 +, Kyle Evans wrote: > > > > +???-- Swap the first two menu entries > > +???menu_entries[1], menu_entries[2] = menu_entries[2], > > +?? menu_entries[1]; > > ? > > IMO, this is the sort of unreadable insanity that comes from having > inflexible rules about line-wrapping which trump readability. ?The > original code could be easily understood. ?The suggested replacement,? > > menu_entries[1], menu_entries[2] = > ? ? menu_entries[2], menu_entries[1] > > Was also pretty readable, although not as much as it would be if it > were all on one line. ?But splitting the line at the whitespace nearest > to 80 columns just creates an unreadable mess for the insignificant > virtue of following some arbitrary rule. ?(Which is why I very often > ignore that rule and split lines at the point < 80 which makes the most > sense for understanding the code, even if that means splitting at > column 30.) +1 Other possibilities are: - moving code to a helper function often removes extra indentation - shorter identifiers (e.g. as a side effect of moving code to a helper function) local function swap_1_2(t) t[1], t[2] = t[2], t[1] end swap_1_2(menu_entries) or local function swap(t, i, j) t[i], t[j] = t[j], t[i] end swap(menu_entries, 1, 2) -- Alex ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r329609 - head/stand/lua
On Mon, Feb 19, 2018 at 4:37 PM, Ian Leporewrote: > On Mon, 2018-02-19 at 22:29 +, Kyle Evans wrote: >> >> + -- Swap the first two menu entries >> + menu_entries[1], menu_entries[2] = menu_entries[2], >> + menu_entries[1]; >> > > IMO, this is the sort of unreadable insanity that comes from having > inflexible rules about line-wrapping which trump readability. The > original code could be easily understood. The suggested replacement, > > menu_entries[1], menu_entries[2] = > menu_entries[2], menu_entries[1] > > Was also pretty readable, although not as much as it would be if it > were all on one line. But splitting the line at the whitespace nearest > to 80 columns just creates an unreadable mess for the insignificant > virtue of following some arbitrary rule. (Which is why I very often > ignore that rule and split lines at the point < 80 which makes the most > sense for understanding the code, even if that means splitting at > column 30.) > Right, perhaps we should clarify this while the opportunity is ripe for style.lua(9) into something more like "80 columns are preferred, wrapping may occur much earlier than 80 columns." I blindly followed it here because we hadn't discussed any exception to it previously, but I think we're more likely in Lua to run into scenarios where the current guideline just isn't appropriate. ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r329609 - head/stand/lua
On Mon, 2018-02-19 at 22:29 +, Kyle Evans wrote: > > + -- Swap the first two menu entries > + menu_entries[1], menu_entries[2] = menu_entries[2], > + menu_entries[1]; > IMO, this is the sort of unreadable insanity that comes from having inflexible rules about line-wrapping which trump readability. The original code could be easily understood. The suggested replacement, menu_entries[1], menu_entries[2] = menu_entries[2], menu_entries[1] Was also pretty readable, although not as much as it would be if it were all on one line. But splitting the line at the whitespace nearest to 80 columns just creates an unreadable mess for the insignificant virtue of following some arbitrary rule. (Which is why I very often ignore that rule and split lines at the point < 80 which makes the most sense for understanding the code, even if that means splitting at column 30.) -- Ian ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r329609 - head/stand/lua
Author: kevans Date: Mon Feb 19 22:29:16 2018 New Revision: 329609 URL: https://svnweb.freebsd.org/changeset/base/329609 Log: stand/lua: Cache swapped menu, and don't create locals for swapping Building the swapped welcome menu (first two items swapped) is kind of a sluggish, because it requires a full (recrusive) shallow copy of the welcome menu. Cache the result of that and re-use it later, instead of building it everytime. While here, don't create temporary locals just for swapping. The following is just as good: x, y = y, x; Reported by: Alexander Nasonov(swapping) Modified: head/stand/lua/menu.lua Modified: head/stand/lua/menu.lua == --- head/stand/lua/menu.lua Mon Feb 19 22:22:35 2018(r329608) +++ head/stand/lua/menu.lua Mon Feb 19 22:29:16 2018(r329609) @@ -138,17 +138,22 @@ menu.welcome = { local menu_entries = menu.welcome.all_entries; -- Swap the first two menu items on single user boot if (core.isSingleUserBoot()) then + -- We'll cache the swapped menu, for performance + if (menu.welcome.swapped_menu ~= nil) then + return menu.welcome.swapped_menu; + end -- Shallow copy the table menu_entries = core.shallowCopyTable(menu_entries); - local multiuser = menu_entries[1]; - local singleuser = menu_entries[2]; + -- Swap the first two menu entries + menu_entries[1], menu_entries[2] = menu_entries[2], + menu_entries[1]; - multiuser.name = multiuser.alternate_name; - singleuser.name = singleuser.alternate_name; - - menu_entries[2] = multiuser; - menu_entries[1] = singleuser; + -- Then set their names to their alternate names + menu_entries[1].name, menu_entries[2].name = + menu_entries[1].alternate_name, + menu_entries[2].alternate_name; + menu.welcome.swapped_menu = menu_entries; end return menu_entries; end, ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"