New answers tagged

2

You were interested in a review in both the pattern as code style. Note: I'm addressing subscribers also as listeners and observers in this review. Code Style Prefer var when the type of the instance is known: NewsChannel newsChannel1 = new NewsChannel(); -> var newsChannel1 = new NewsChannel(); Use expression-bodied members for compact code blocks. For ...


1

Rubocop Report connectedCell Avoid nested code blocks if clean alternative statements are available. For instance, in method connectedCell you have the following block: if matrix[i][j] == 1 # .. code omitted end Replace the if-statement with next unless matrix[i][j] == 1 and you'll be able to reduce nesting with 1 level. The next part has a similar ...


1

I really like clear and speaking method names, I quickly tried to refactor the first method but have had not much time, I hope this helps anyway. I have not understand the other initialization of the visited hash in the area_count method (yet). The new neighbors method indeed looks some kind of overloaded with information, no good idea yet how to change it,...


1

Although you already accepted an answer, here is my two cents. The code: Although recursive functions can lead to elegant solutions for some problems, in addElement() I think the recursive call complicates things. So I changed that to an iterative solution, and kept track of the column index. The function is also complicated by terminating the loops when ...


1

Earlier today I was driving home and came across this question, and thought of a method to do this in seconds. Each message has a 'chunk' depending on the amount of rows. In the example, this is the first chunk: P A P Y Each chunk uses the same indexes from the rest of the message. And so you can do a simple slice, message[start::chunk_size]. The size of ...


1

Please don't get me wrong. The code works. Working code is a good thing. Working code that might break is not broken code. Fundamentals Starting a Python module (or file in any language) with a comment describing what problem the code solves is helpful. It helps reviewers and future users understand what the programmer is trying to do. More importantly, it ...


3

As you pointed out, you don't actually need to lay the characters out into a grid. It would be more efficient to use arithmetic to figure out the indexes of the characters in each row. For example, if num_rows is 3, then each down-up cycle will consist of 4 characters. (zigzag_size = 2 * num_rows - 2). Then we also know that the top of each zigzag will ...


1

Most people are talking about code style, optimization, and documentation, but to me those things aren't typically that vital. I know people will get on my case about that, but here's my reasoning. Although those things are VERY important, none of your code is so poorly optimized that it makes a serious impact on performance. Other things would definitely ...


2

(The question is more than two years old, and both Xcode and Swift have been developed substantially in that time. The following review is written with the current Xcode 10.3 and Swift 5 in mind.) Creating the user interface Both the Objective-C and the Swift implementation create the user interface purely in code, which is laborious and error-prone. There ...


1

Review Your SQL seems the generally accepted way (Discussed Before) of deleting duplicates. WITH cte AS (SELECT id, student_code, exam_code, mark, Row_number() OVER( partition BY id, student_code, exam_code, mark ORDER BY ...


Top 50 recent answers are included