Pablo Aguirre

Greenhorn
+ Follow
since Apr 04, 2020
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Pablo Aguirre

Junilu Lacar wrote:The name FileProcessor is also vague whereas the JavaDocs are very specific. If the JavaDocs fully explain the reason for this class' existence, then maybe you can find a name that better reflects that purpose.



I decided to use another class mainly for practice purposes. In this case what would you suggest for the name of the class? Something more specific? FileEditor, FileCopy, FileCopyAndAppend ?

Thanks!!
4 years ago

Junilu Lacar wrote:

feel free to tear it apart


Ok...
A program should tell a story. This program doesn't tell its story very well. It starts out being very vague about what it's doing by creating a FileProcessor object and then calling that object's copyFile() method. Nothing else in that code gives the reader any kind of context on what they should expect, except the error handling boilerplate around the call to copyFile(). What file is being copied? Where is it getting copied to? The code is very mysterious-looking.



Ok, starting from here. What would be your suggestion about how to achieve this? My first modification was to add info in a javadoc block.

4 years ago

Junilu Lacar wrote:

Pablo Aguirre wrote:I'm replicating a question I posted on stackexchange so here's the link if you want to check out some opinions.


Thanks for informing people that you've posted the same question elsewhere. You missed adding the link though so here's the one I found: https://codereview.stackexchange.com/questions/243005/architecture-and-error-handling-in-simple-java-program



Thank you for taking the time to reply! Yeah, I forgot to add the link, sorry. I'll rethink the code with your reply in mind. I had another comprehensive reply on stackexchange that suggests a couple of the same things. I'll probably come back soon with more questions about your reply :-D
4 years ago
I'm replicating a question I posted on stackexchange so here's the link if you want to check out some opinions. Code review is in my opinion the single most valuable way to improve my code so any feedback is appreciated.

----
I'm trying to get my basic coding principles right but there's still a long way to go. This is an exercise for CodeGym. They logic itself isn't very hard and I passed the exercise easily but I'd like my code reviewed with the following in mind:

- In terms of the general architecture, I wasn't quite sure if I needed two methods. It felt tidier to me to have a method for the first task (copy) and one for the second (append) but I couldn't figure out a way to avoid calling the second method from the first.

- Should read the inputs from the console in the main method and pass the result to the class? Or it totally depends on the context of the application I'm working for?

- About error handling, I got completely lost. After doing some research I just decided to let the caller handle the error but I'm sure there's some stuff missing. I wasn't sure for example if I should have two try blocks on the first method but it also depended on the answer to the first point (architecture), so I gave up.

- It's my first time using Javadocs, so I'm not sure what I wrote is enough.

- I know "Solution" is not the ideal name for the class, but I used the class created by CodeGym.

Please feel free to tear it apart

Thanks in advance!



4 years ago

Zachary Griggs wrote:

I don't think countCommas should declare that it throws an IOException
You catch IOException here. You could also move the lines above (that may throw IOException) into this try block.

So it can't throw any IOException.



I'm doing my next exercise and trying to close a method using the finally block and I'm getting an error telling me I should declare the method throws an IOException.

I tried moving the declarations into the try block but then the variable can't be reached. Any thoughts? Here's the link for the image:

https://imgur.com/a/fqD5LIN

Edit:

I fixed it using the code below but not sure if it's correct.

4 years ago
Zachary Griggs, Fantastic stuff, thank you so much for the comments, I'll definitely think about all of that for writing code from now on. From your comments I realised I have zero consideration for readability.
4 years ago
I've been trying to follow advice from this amazing forum and from now on my objective isn't only to pass the tests, but also write using good practices. So I'll be posting some exercises to be critiqued:

For this exercise, my changes were:
1 - Avoid writing all the code in the main method
2 - Pay closer attention to exception throwing
3 - Close the stream properly

Just FYI, the "Solution" class was given beforehand by the exercise.

Please tear my code apart!

4 years ago
Thanks everyone for the amazing answers! I'll come back with more exercise solutions for you guys to tear apart soon haha
4 years ago
Hi! Thanks for your reply. I really appreciate your feedback.

The exercise is from CodeGym. It's the best resource I found so far because it's exercise and projects based and that's the way I learn best. The student's solutions are checked automatic by some IntelliJ plugin they have. Not sure you can open if you're not logged in : Codegym Exercise


Yeah, my solution is too complicated, I used a solution based on a HashMap and it simplified things. But I'll try to create an object as you suggested.

I'm using .close() based on this : http://tutorials.jenkov.com/java-io/fileinputstream.html. Why shouldn't i use it?

Thanks!!
4 years ago
Hey folks!

I came across this exercise where I have the most frequent bytes on file and display them.  I have two questions:

1 - Should I use my time to try to solve this or this is just a mind twister that won't be helpful in the future?

2 - I tried an approach without HashMaps. I created a byte array, sorted it, found the most frequent item and the frequency and then looped again to add any items with Max Frequency to a result ArrayList<byte>. But the exercise is not passing the automatic check. Here's the code. Is the code doing what I think it's doing? Adding all the most frequent bytes to the result ArrayList?

Any comments about bad practices or different approaches are also appreciated:

4 years ago

Junilu Lacar wrote:

Does this clear up some things for you?



I'll need a bit of time to study your post, haha. Then I'll get back to you. Thanks so much!

Question, what's a good code simulator for Java for people to work in a project simultaneously? Something equivalent to stackblitz for Angular. I think it's a great tool for study.

4 years ago

Junilu Lacar wrote:

Pablo Aguirre wrote:I'm still a bit confused with the names of the variables. ... I'm assuming the y,x variables in the if statement are the ones in the game object, not the new ones created to run the loop?


If you're referring to the y and x here:

for (int y = ... ) {
   for (int x = ... ) {

then yes, they are the ones referred to in the if-statements. The gameObject x and y fields are qualified: gameObject.x and gameObject.y.

Shouldn't they have a different name to make it easier to visualize? (a,b) or whatever. Or what am I missing? Again thanks a lot for the invaluable replies.


They could have different names but I doubt (a, b) would make their intent any clearer. 'neighborX' and 'neighborY' maybe but that's a little wordy. In this case, I don't actually mind y and x that much.

I could suggest at least one different way that is more object-oriented but that would take us a whole 'nother path that you might not be ready to go down right now.



After creating this little test I finally understood that writing for (int a = gameObject.y - 1; a <= gameObject.y + 1; a++)  because the number in the matrix depends on the number of the coordinates.

4 years ago

Tim Holloway wrote:OK. The object is to create a List og GameObject's that are adjacent to a specified GameObject. This is done by scanning the following potential matrix, which is overlaid on the board matrix:


Note that the center cell is omitted, since that's where the reference GameObject itself lies.

We increment the x and y co-ordinates from relative -1 to relative +1, indexing the x co-ordinate the fastest. Or, in other words, scan by row, then column going left-to-right and top-to-bottom.

Hower, the gameboard is of finite dimensions, so co-ordinate positions that fall off the edge of the board (board co-ordinates of less than 0 or more than the board width and height) are ignored, since they don't exist and would throw an ArrayIndexException if you tried to use them.

Given those constraints, the eligible cells are each checked for the presence of another GameObject, and if present, that GameObject is added to the returned list. If there are no adjacent objects, an empty list will be returned.



I'm still a bit confused with the names of the variables. After your explanation I understand what the loop is doing, but when trying to simulate the loop starting on int y = -1, x=-1 (if y<0 || y>=side). I'm assuming the y,x variables in the if statement are the ones in the game object, not the new ones created to run the loop? Shouldn't they have a different name to make it easier to visualize? (a,b) or whatever. Or what am I missing? Again thanks a lot for the invaluable replies.
4 years ago

Junilu Lacar wrote:It looks like the code assumes that all cells on the gameField have gameObjects in them. Maybe an empty cell is also represented by a special kind of GameObject instance.



Thanks for all the replies, I'm still trying to make sense of the code as it's slightly above my head. I think yes, the previous code assumes there are no empty cells. In a different method all the cells are filled a GameObject:

4 years ago