1 Mazuzahn

Robocop Assignment Branch Condition Size For Create Is Too High

A loner with a lot of growing up to do, Rian is an 18-year-old senior at Chelmsford High School in Massachusetts. He spends his Friday nights drinking milk alone at his kitchen table because his only friends are the stuffed ones that clutter his room. In fact, Rian has such an affinity for toys that he spends most of his free time working at KB Toys.Rian has a hard time fitting in -- and not just because of his love for Teenage Mutant Ninja Turtles and SpongeBob SquarePants. Rian has Asperger's Syndrome, a type of autism that inhibits social interaction. As a result, he finds it hard to make friends, and he has never had a girlfriend. That's why he wants to compete in his school's annual talent show and be MADE into Mr. Chelmsford High School so that he can show people that his disability does not define who he is.Despite his determination to reach his lofty goal, when Rian signs up for the Mr. CHS talent show, he immediately realizes he is out of his league. While Rian practices dancing alongside the other contestants, his MADE coach, Jackie Bruno, Miss Massachusetts 2008, surprises him. Leaving the other contestants behind with their jaws dropped, Rian leaves with Jackie and talks to her about why he wants to win the talent show. Jackie warns Rian they have a lot of work to do, from finding him an escort to working on his talent to perfecting his dance moves.The next morning, Jackie takes a look at Rian's bedroom and tells him he is going to need to get rid of all the stuffed animals and toys if he ever wants a girl to come over. The next day at school, the ultimate bombshell is dropped when Rian learns that this year's Mr. CHS contestants must appear onstage in swimwear!Early the next morning, Rian gets a rude awakening from his personal trainer, John. To get swimsuit ready, he must hit the gym. In addition to working out, must start to sharpen his moves on the dance floor, which includes walking in high heels so he can practice balance and grace.While Rian thinks that KB Toys will be a place to relax and escape all his talent show prep, MADE coach Jackie Bruno has other plans. At work, Rian is approached by three Miss USA contestants who all pretend they are customers. Then, Rian learns that he will be going on a dinner date with them and Jackie so he can hopefully get comfortable talking to women. At dinner, Rian reveals he has a long-time crush on his classmate Jen, and Jackie gives him an assignment: to ask Jen out on a date.The next day at school, Rian is rejected by Jen when he asks her to a movie. But he doesn't let this heartbreak stop him. He moves on to the next girl, asking out his math class crush Taylor -- and she says yes!Having found a potential escort, Rian shows his talent to Jackie, but his embarrassing version of "When the Saints Go Marching In" on the sax just doesn't cut it. After asking his fellow classmates what they think he is good at, Rian decides he will perform a stand-up comedy routine. Rian tries his first stand-up act in front of the other Mr. CHS contestants. But while he thinks he's funny, the silence in the room makes it clear the other contestants don't.To work on his routine, Rian heads to an improv class. To his surprise, he really feels in his element; the crazier the routine, the more comfortable he feels. During some one-on-one time with improv coach Dana after class, she encourages him to embrace his uniqueness and even crack a few jokes about his Asperger's Syndrome.Before dawn the next day, Dana wakes up Rian and surprises him with a trip to Georgia, where he will watch see comedian Josh Blue, who has cerebral palsy and was the winner of Last Comic Standing, perform. Josh proves to Rian that even if you have a disability you can be successful and encourages Rian to try joking about Asperger's Syndrome in a debut comedy routine that night. The crowd loves his set and Rian conquers his stage fright.Before leaving Georgia, MADE coach Jackie Bruno has another surprise for Rian. He meets with Heather Kuzmich, a contestant on America's Next Top Model who also has Asperger's Syndrome. She helps build up his confidence for the Mr. CHS talent show after talking about her own experience with the disability.It's finally time for Rian's much anticipated date with Taylor. Instead of going to the movies, they take a trip to the fire department so Rian can donate all his toys. Taylor has a great time on the date and agrees to be Rian's escort for the talent show.After getting a style overhaul, Rian is ready to put his new buff bod and comedy routine to the test in hopes of becoming Mr. CHS. Rian rocks it on the dance floor, kills it in the swimsuit competition and even has the audience in hysterics during his comedy routine. Although Rian isn't the winner, people now see him in a whole new light. He is no longer an awkward loner; he is relaxed, confident and MADE.

Understanding Assignment Branch Condition

Recently, I integrated Rubocop into my work flow and it’s been very humbling. I feel I’m a great coder with all the specs passing and doing a good job of refactoring, Rubocop always finds something wrong with my code.

I usually go back and make fixes based on Rubocop’s suggestions, but I keep running into the same few issues and solving them isn’t as easy as using: (which auto-corrects all the easy ones!)

The toughest offense for me so far: Assignment Branch Condition

This offense is harder to fix really make me think about my coding style in general. I want to learn more about this offense to help me understand. By understanding, my goals is to not make this offense so often and/or make it easier for me to fix in the future.

What is: ABC?

Rubocop message:

The default is 15 and the first pass of my code is always way past this, probably on average twice this value. So cleaning up my code to meet the default value really takes a lot of work.

From the documentation:

Really Understanding: ABC

Let’s understand what ABC is by checking out the definition of ABC:

Broken down:

  • assignments (anything with )
  • branches (anything that jumps out of the current method)
  • conditionals (anything that tests logic , , unary )

SO, to reduce the ABC value, reduce assignments (use less intermediate variables), fewer branches (calling other methods), and conditionals (if/else statements).

Computing ABC

The ABC value is not just a counting of them, but a square root of the sum of their squares. If any one of them getting too high will spike the ABC count.

The Rubocop default for ABC metric is 15. What does 15 really mean?

Well, doing the math, to get an ABC score of 15, a method would have:

  • 8 assignments
  • 8 branches
  • 8 conditionals

(Just working backwards from 15*15 => 225; 225/3 => 75; Math.sqrt(75) ~=> 8.66)

Now that I lay it out that way, an ABC value of 15 is very reasonable. Having eight of each for a method is just enough to do a lot of work in a method, but a value of 15 keeps the method from spiraling out of control in assignments, branches, or conditionals.

Conclusion

Whenever I encountered Rubocop’s ‘ABC is too high’ message, I was annoyed with ABC metric because I didn’t understand how it was computed and I couldn’t refactor efficiently to lower the ABC value quickly.

Now that I spent some effort into researching what Assignment Branch Condition really means, I feel better about creating or refactoring code that has a better ABC score.

Leave a Comment

(0 Comments)

Your email address will not be published. Required fields are marked *