General statistics
List of Youtube channels
Youtube commenter search
Distinguished comments
About
Lawrence D’Oliveiro
Fireship
comments
Comments by "Lawrence D’Oliveiro" (@lawrencedoliveiro9104) on "Reacting to Controversial Opinions of Software Engineers" video.
In other words, you cannot properly automate GUI testing, but algorithms can certainly be tested.
16
One thing experience teaches you is to hold off on optimization until you get the code actually working correctly. I revisited a personal command-line script of mine a few days ago. It was taking about 6 seconds to start each time. I soon discovered a couple of things: * Importing matplotlib is quite slow. So if I defer that to the actual plotting function, so it only gets imported if I use that function, that speeds up the invocation of other functions. * When computing stats over a particular sampling interval, my database query was iterating through all the samples and discarding ones outside the range, because I couldn’t be bothered narrowing things down within the query itself. That made sense at the time, but now I have accumulated over 150,000 sample records, it was time to revisit this decision. So I added a couple of extra queries to determine more appropriate time bounds for the actual query for samples. As a result, displaying accumulated counts over the last 30 days went from 6 seconds down to about 1 second.
2
I have done “clever” things. In one recent Python project, I wanted to support both synchronous and asynchronous versions of the main API classes. So I implemented a mechanism involving processing the parsed ASTs for those class definitions to generate two versions of each. That way I could write all the common code just once. The final size of the module was about 2500 lines. The code for implementing the macro-processing mechanism is about 160 lines (including comments explaining in detail how it works). If I wrote out all the expanded code by hand, it would add about 1000 lines to the code size. Less of course the macro processor, so the net gain is say 840 lines. Less code means less effort to write, and less effort to maintain, and less chance for bugs to get in. In my view, a net gain. And quite a significant one.
1
Here’s an example of commented code that I write: my_wait_avail = asyncio.get_running_loop().create_future() if self.wait_avail != None : # somebody else using this socket -- wait till they’re done await self.wait_avail ♯end if assert self.wait_avail == None self.wait_avail = my_wait_avail # claim ownership of socket Now, would you suggest getting rid of those comments, or not?
1
@hamm8934 Show us how you would do it, then.
1
@aoeu256 Tools exist, but they don’t work reliably.
1
Java is just way too wordy and convoluted. One example is the whole “Selector” mechanism for managing nondeterministic I/O. It’s something like 4 different classes and I don’t remember how many dozen methods. For comparison, Python sums it all up in its “select” module, where you only need one class with just a few methods.
1
@CottidaeSEA So is there some simpler alternative to the “Selector” mechanism now? Enquiring minds would like to know.
1
@CottidaeSEA Just look at the APIs I mentioned, and compare them.
1
@CottidaeSEA In Python I can wait on a file descriptor with just 3 calls: * Create a poll object * Register my FD * call poll.poll(), with or without a timeout. Try doing the equivalent in Java.
1
@CottidaeSEA Show us some code to demonstrate how you do FD selection.
1
@CottidaeSEA And laziness, too, is one of the three programmer virtues, according to Larry Wall. This is the kind of code I had to add to narrow down the query interval (×2, this one for the lower limit, another similar one for the upper limit): limit = eval_expr \ ( conn, "min(artwork_timestamp) from" " (select max(timestamp) as artwork_timestamp from" " artwork_stats inner join artworks on" " artwork_stats.artwork_url = artworks.artwork_url where" " artworks.artwork_url in (%(artworks)s) and timestamp <= %(since)d" " group by artwork_stats.artwork_url)" # minimum of latest sample for each artwork that is not after since % { "artworks" : ", ".join(sqlite.format_sql_value(a) for a in prev_timestamp), "since" : since, } ) if limit != None : where.append("timestamp >= %d" % limit) ♯end if You can see why I avoided doing it until it became necessary.
1
@CottidaeSEA The triply-quoted strings introduce spurious whitespace. Suddenly the query doesn’t look so neat.
1
@CottidaeSEA I also consider readability of the query itself.
1
@CottidaeSEA You don’t like the way I write my code. So sue me.
1
@DjoumyDjoums Code performance generally follows a pareto distribution. Find and speed up the performance bottlenecks, and that improves things overall. As in my example.
1