Avoiding the hip-hop comics?
My favorite part is defining a verse(number) function that takes a parameter which completely changes the output, pointlessly bundling all the verses into one big logical blob and necessitating a bunch of conditional testing to figure out what to do when called. Instead, the verses could be saved off into discrete verse1(), verse2(), and verse3() functions that allow verses to be moved around willy-nilly, as described in the article.
Maybe the programmer is trying to suggest that the lyrical content of each verse is somehow procedurally related, and that there are optimizations to be had by providing a single entry point for generating them⌠nah. Thatâs not whatâs happening. My guess is that, since lyrics tend to NOT be procedurally generated, this is just a bad design.
Worse, using an ordinal to identify which verse is which is contrary to the goal of reordering them. Why would anyone think adding the ability to do this:
verse(2)
verse(1)
verse(3)
âŚis remotely sensible? The âfirstâ verse is now the âsecondâ verse, the second is the first, and only the third reflects itâs actual location in the song, by ordinal index. All weâve done here is add an unnecessary layer of indirection that we can use to confuse ourselves about what the code is actually accomplishing.
You donât design good code to put cool coding techniques into practice, you design it to reflect your intent. The implied intent of this design is âsupporting the rearrangement of versesâ which in the practical world of linear narratives is pretty darn useless. By providing that capability, youâre basically asking someone to use your code to do bad things. A good framework will not include these capabilities, thereby steering programmers into to using it correctly.
Youâre overcomplicating the issue. The point is to realize that you can define functions in a program in one place, and then call then in the main function whenever you want.
I didnât include an option with verses 2 before 1 and 3 so not sure where you got that from, but it can make sense in terms of music ! There are hip hop songs that are originally written one way, and then the verses are switched around later.
All programmers do it differently.
Um ⌠Thanks for the feedback?
Let me elaborate on my earlier, snarky comic reply.
Youâve mistaken this article for a programming tutorial. It is not actually trying to show you the best way to write a program that prints the lyrics to a single song. (Why would you even want to do that?) Shareef Jackson is a STEM diversity activist; heâs drawing a parallel between coding and hip hop (something many black kids will be familiar with) in order to show black kids that coding is something they can understand and do, and hopefully get them interested in the technical fields that are so dominated by white dudes. Using Verse(1) allows him to explain how functions (and specifically function parameters) work in a way that wouldnât have been possible if he only used functions without parameters.
This topic was automatically closed after 5 days. New replies are no longer allowed.