3 ms·
I completely agree (tho you're getting downvoted by others). Linus's code here is 'clever'... but not good, simple code.
by TickleSteve 10y ago
I completely agree (tho you're getting downvoted by others).
Linus's code here is 'clever'... but not good, simple code.
- kwhitefoot 10y agoIt's a long time since I wrote much C but Linus' version seems like idiomatic C to me. The use of pointers in C is an ordinary thing and those who write a lot of C should be fluent in their use. It's interesting to apply the same technique to other languages. I have to use VB.net most of the time so here are implementations of the tasteless and tasteful versions in VB (untested so there might be bugs). Even in VB the tasteful version is shorter and, I think, clearer. Module Module1 Public Class ListEntry Public value As String Public [next] As ListEntry End Class Public Head As ListEntry ''' <summary> ''' Straight translation of Torvalds' tasteless version. ''' </summary> ''' <param name="entry"></param> Sub RemoveListEntry(entry As ListEntry) Dim prev As ListEntry = Nothing Dim walk = Head ' Walk the list While walk IsNot entry prev = walk walk = walk.next End While ' Remove the entry by updating the head or the previous entry. If prev Is Nothing Then Head = entry.next Else prev.next = entry.next End If End Sub ''' <summary> ''' Straight translation of Torvalds' tasteful version. ''' </summary> ''' <param name="entry"></param> Sub RemoveListEntry1(entry As ListEntry) Dim indirect = New ListEntry indirect.next = Head ' Walk the list looking for the thing that points at the thing that we ' want to remove. While indirect.next IsNot entry indirect = indirect.next End While ' ... and just remove it. indirect.next = entry.next End Sub End Module
- deleted 10y ago[deleted]