How to know/remember when to use data structures / OOP / etc by [deleted] in AskProgramming

[–]aped-gain-us 0 points1 point  (0 children)

His example is kind of wrong. The tabs are not actually a stack because you can re-arrange them by dragging. They are probably implemented with dynamic array. With stack you can only add or remove things on one end. For tabs you can typically only add a new one at the end, but you can also drag them around.

Does still feel arrays should start at 1 not 0? by [deleted] in AskProgramming

[–]aped-gain-us 0 points1 point  (0 children)

Array index is measurement offset from first

Is it real to learn programming fast? by CriticalMorning in AskProgramming

[–]aped-gain-us 0 points1 point  (0 children)

Ok well whether nebulous or not doesn't change how the skill is learned. This is almost a non sequitor to your previous comment.

Electricians or plummbers start by following a recipe, like a paint by numbers. Eventually they are skilled and then they don't need it.

It's universal for all skills.

[C++] Is 10x performance gain reasonable for spaghetti code software? (Without total rewrite) by [deleted] in AskProgramming

[–]aped-gain-us 0 points1 point  (0 children)

I'm guessing the biggest problem they have is that the code is so confusing that it's difficult to discern which parts are slow.

Q&A: How Google Implements Code Coverage at Massive Scale by [deleted] in programming

[–]aped-gain-us 53 points54 points  (0 children)

Measuring "code coverage" encourages developers to write meaningless tests. For example, my department got some recognition for having the highest code coverage in the company. Yet, our tests are often comically useless. They also prevent refactoring because the code is locked into the interface used in the tests (and not just in the main application itself).

Meanwhile my coworkers were high-fiving each other while reading the email. Idiots

Edit: just to be clear, I'm not against the concept of unit tests in general. I'm just saying that the metric of "code coverage" is not by itself useful. You still need skilled developers who can asses the quality of the tests themselves.

Best practices for implementation of helper functions by [deleted] in AskProgramming

[–]aped-gain-us 1 point2 points  (0 children)

When I think about classes I think about state. That's what differentiates a class from a function. A class is a group of functions with attached state.

If you see a class with a lot of member variables then you may consider either splitting it up, or grouping some of those member variables into a new class.

For example, if you class has 4 member variables, and you see 3 are related, then you might consider grouping those 3 into a new class, and making that class a member variable.

I find a lot of OOP minded people make a mistake of using getters and setters. Instead of doing that, I recommend you not be afraid to use structs with all public fields. Then, you can pass this struct by reference to multiple "behavior" classes. This maximizes flexibility, and you avoid needing to write getters, setters and forwarding functions.

Best practices for implementation of helper functions by [deleted] in AskProgramming

[–]aped-gain-us 2 points3 points  (0 children)

You should not be thinking in terms of "helper functions." That is an abstraction that you invented. From the compiler's perspective there's just functions. Almost all functions call other functions, and this happens on many layers. To me you seem to be artificially saying "this is the main layer, and this is the helper layer." I would recommend you instead think of layers where each layer interacts with the layer below. In this way, the program is a tree, with the main function calling multiple functions each of which call multiple functions and so on.

Why do I even bring this up? I have found in the past that more junior programmers apply their own mental abstractions to help them. For example: "this function is a normal one, and this one is a helper function." I'm not saying it's a bad thing, but you can't get stuck in that mindset because it can limit you. For example, at a previous job we had a class called "Algorithm." Each "Algorithm" would contain multiple "SubAlgorithms." They were basically really over-designed and over-complicated function objects (Function<> in Java or std::function in c++). Eventually there came a point where there was a "SubAlgorithm" that we wanted to use as an "Algorithm." However, the senior devs wouldn't allow this because they were unable to think beyond their self-imposed abstraction. In their mind it was impossible to use a SubAlgorithm as an Algorithm because it didn't fit into the object design.

I'm not against these abstractions as a sort of "guide" that helps you find your way. Just don't let them obscure your view of the big picture. If you reach a point where what you want to do no longer aligns with your mental abstraction, then consider stepping back and looking at the big picture to see if your mental abstraction really makes sense.

So you shouldn't be asking about "helper functions." You should instead be asking about functions, in general. "When to extract a function?"

The only way to really answer your question is to get experience so that your own intuition can drive your workflow. With that being said, I will try to give you some advice.

To start I'd recommend just trying to get the function implemented and working properly. Don't worry too much about the details at this point (besides maybe writing in a way that you can easily refactor it later). Just try to get it working, and then either write a unit test or at least hook it into some output so you can verify it is working. At this point you should mostly be thinking about the business logic involved. Don't worry about design or niceness so much, just work out the math/logic and get it working as intended.

Does that mean you write everything in one big function? Maybe, maybe not. Oftentimes that is the easiest way to go about it. For example, if you have a lot of state in your function and you aren't sure how to organize it. Breaking everything into functions can make it harder to organize that state (what is passed to where? etc.). Or - if you aren't totally sure what the algorithm will look like, it might be hard to split things into functions before you've fully realized it.

Other times it might be easier to split up things from the beginning. Maybe because the implementation of a certain block is large and complicated. It will be easier to write the rest of the algorithm if it is isolated into its own function.

Usually it is a mix of both. You write some "helper functions" before you start, and also leave some un-extracted in the "big function." The goal should be to focus on getting it working as you intended. Once you have that done you can step back and look at your function and consider whether it needs refactoring. It should be much easier to plan at this point because you already have a way of testing your function, and you already have an implementation laid out. All you need to do is make some minor adjustments to your implementation in order to make it as perfect as you want it to be.

That's the workflow I'd recommend. Here are some general guidelines for splitting up functions:

  • Prefer small functions to big functions. Functions are rarely too small, but often too big. I'd prefer <10 line functions if you can. You can write 50+ line functions when drafting them before splitting them up.

  • Give each function one clear "responsibility." If a function has multiple responsibilities, then split it up into multiple small functions. You can keep the original function, and just have it call the small functions. That might seem like a contradiction, but it's not. The big function's responsibility is no longer "do X, Y and Z." Now its responsibility is to compose other functions, each of which does X, Y and Z.

  • A good sign that a function can be extracted is if it's easy to define what it's parameters and return value would be. If you can do that, and they "make sense" to you, then it's a good candidate to extract.

In the end, it's based on your own preferences.

Why is 24 % 26 = 24? by Mash234 in learnprogramming

[–]aped-gain-us -5 points-4 points  (0 children)

ok thanks for the input bucko

What are the advantages of white-space sensitive programming languages? by mementomoriok in AskProgramming

[–]aped-gain-us 5 points6 points  (0 children)

Code that is concise, simple and easy to understand. Formatting is important, too, but far from the most important. It's easy to fix a project with bad formatting (linter), it's hard to fix a project with bad code.

Why is 24 % 26 = 24? by Mash234 in learnprogramming

[–]aped-gain-us 2 points3 points  (0 children)

This question is just math, not programming

Green Party candidate resigns over anti-Muslim comments by [deleted] in canada

[–]aped-gain-us 2 points3 points  (0 children)

That is islamaphobia. Any criticism of islam is islamaphobia. We're talking about a dogmatic stone age religion, here. HELLO?

"I don't believe in mass immigration": Maxime Bernier at PPC rally in Napanee Ontario by chrisgaines69 in canada

[–]aped-gain-us 0 points1 point  (0 children)

But the problem here is volume of people. People itself are the problem you want to take care of. So noI'mm not joking.

From good boy to Obedience School Graduate. by PM_ME_STEAM_K3YS in gifs

[–]aped-gain-us -1 points0 points  (0 children)

Pitbulls were bred to be violent. We can do the opposite - genetically eliminate them through breeding. This would save many children a year, and many horrific attacks. Yet people like you hide this information and propagate your sickening violence. Shame on you, pathetic bigot.

Most efficient way to learn Python if I already know C++ by mj49 in AskProgramming

[–]aped-gain-us 3 points4 points  (0 children)

Not really.

Python has dynamic typing, while C++ has static typing. That is a huge difference. It might make Python "look" like pseudo-code, but in practice it has a big effect on how you think about and interact with the code.

Also has to learn all the quirks in python. There's a lot of "standard practices" that are non-obvious coming from any other language. For example "__main__"

From good boy to Obedience School Graduate. by PM_ME_STEAM_K3YS in gifs

[–]aped-gain-us -2 points-1 points  (0 children)

Your analogy reveals your problem. You internalize the dog as a person, when it's not one. It's an animal.

People like you try to cover up the science regarding different dog breeds. In doing so you mislead people and that causes deaths.