Skip to content

Portfolio#3

Open
Josiah-Caldwell wants to merge 2 commits intomasterfrom
portfolio
Open

Portfolio#3
Josiah-Caldwell wants to merge 2 commits intomasterfrom
portfolio

Conversation

@Josiah-Caldwell
Copy link
Owner

Complete Week 3
Add functional comments
Change color scheme

Copy link
Collaborator

@gradywardgoogle gradywardgoogle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Josiah, great work. This code is exceptionally clear, well formatted, consistent and readable. I've rarely seen this level of attention to detail from interns, and I really appreciate how easy it makes my review process! Keep up the good work.

/** Servlet that returns some example content. TODO: modify this file to handle comments data */
@WebServlet("/data")
public class DataServlet extends HttpServlet {
ArrayList<String> employeeComment = new ArrayList<String>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor this to get it to the point where we don't store state in the servlet? Ideally every reuqest we make to the servlet will be independent from any other request - and state in the servlet seems to counter-act that.

I think this could just be a method variable in doGet, right? then you could pass it into getNumComments.

try {
requestedNum = Integer.parseInt(userNum);
} catch (NumberFormatException e) {
System.err.println("Could not convert to int: " + userNum);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely appreciate the error handling! But instead of using print statments, let's throw an exception (perhaps an IllegalArgumentException here). In general, we want to code defensively, which means we want to fail requests that are poorly formed, or don't conform to our expectations. Throwing an exception is a good way to indicate that to the calling user (whether that's Javscript that you write, or an accessor of your API).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do that throughout? IllegalArgumentExceptions are a good semantic choice in many cases (where you're validating the input of a user), but so are IllegalStateExceptions (when you're validating an assumption you have about what a function or datastore will contain/return)


//Limit the number of comments
for(int i = 0; i < getNumComments(request); i++) {
response.setContentType("text/html;");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this probably shouldn't go in the for loop? We probably only need to set it once.

<p>My name is Josiah Caldwell, I am a computer science student at
<div id="section">

<p><img src="/images/Mark.png" alt="Mark of the Outsider" id="Mark">My name is Josiah Caldwell, I am a computer science student at
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meganit: we'll want to use lower-dash-case for HTML classes and IDs. This isn't a huge deal, but it will be helpful as we build up a bigger code base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants