News for hackers. Stuff that matters.

JZN666

Re:Ask HN: What do you consider as “bad” code? on Tuesday January 25, 2022 @09:46AM (#30072295)
> Code with lots of microdependencies to perform really trivial tasks.

"trivial" measure highly relies on programmer's/developer's experience and knowledge. For first developer traversing a tree and applying some updates based on nodes conditions would be "trivial" so thee places all the code in one function. For second developer the same problem would not be such trivial, so thee creates two functions "fn listFromNodes<T, U>(t: Tree<T>, pred: (fn(e: T) -> bool), map: (fn(e: T) -> U)) -> List<U>" and "fn applyUpdates(updates List<Update>)".

> Uncommented code

Why comment a code that's mapped to problem trivially observably (ex. if it's code describing some GUI component with style fields and your task is change style of its part)? I prefer commenting code that contains complex logic (which is measured through code reviews, developers skills, calls etc.) and its effects aren't observed obviously.

> Commented-Out code (git exists for a reason)

Yes and no. Commented-out code is usually in-place saved draft of old code. If some bug is encountered with new code, you can comment-out new code and uncomment-out old code quickly to discover a bug in new code later. Git is less easy to accomplish this task.

> Inconsistent naming

Some rudiment not quickly refactored, may be involved. Example, I had a project when I had type "CardRef" which initially contained only a name (string) of card which was used as a reference for it. Then I decided to include some scores for a card to selecting cards smarter. I kept a name for type the same because it was used a lot in a project for related entities.

Re:Ask HN: What do you consider as “bad” code? on Tuesday January 25, 2022 @07:48AM (#30071180)
> Can you absorb or re-absorb what it is doing rapidly by looking it over for a few seconds?

No. Not only because code is essentially poorly structured, but also because I'm not fluent in subject behind a code. Example is operating systems: when I look in Linux's source code for example, I can't understand which problem is solved by each routine. But does that make Linux source code "poor structured"?

Re:Ask HN: What do you consider as “bad” code? on Tuesday January 25, 2022 @07:40AM (#30071119)
These properties can be inherited from model/organization itself except "difficult to understand for wrong reasons" and "doesn't work" perhaps. So that's why I point to "respecting to model", a more generic take imho.
Re:Ask HN: What do you consider as “bad” code? on Tuesday January 25, 2022 @07:34AM (#30071084)
> non-neccessary complexity with regards to given model (problem, tools)
Re:Ask HN: What do you consider as “bad” code? on Tuesday January 25, 2022 @07:33AM (#30071075)
This looks like one of my points: "non-neccessary complexity". Why using "echo" statements if PHP is already designed as procedural web-templating language? If it's not a function that dynamically renders template based on some params.
Re:Ask HN: What do you consider as “bad” code? on Tuesday January 25, 2022 @07:22AM (#30070983)
* and decomposing a function in smaller functions

Ask HN: What do you consider as “bad” code?

My opinion about this constantly changes through my programming experience. Functions longer than 20 lines of code? Pffff, an algorithm/problem can be such complex in nutshell and decomposing a function solving it will be non-relevant (see any std library of PL). Mutable global state? Pfff, anything in software is based on that, the problem is using it properly in target architecture (ex. in...

( Read More... | 36 comments | 13 points | on HN )

Ask HN: What is your best type of technical interview?

I encountered several types of interview through companies of different values (small startup to big tech). First kind is Leetcode-style interview where your task is to write algorithm/data structure to solve given problems. Second kind discards algorithmic problems treating them as "uneffective" method to choose developers who can produce maintainable, well scalable code. They prefer problems...

( Read More... | no comments | 2 points | on HN )
Re:Ask HN: What can lead to misleading names of functions? on Friday November 26, 2021 @01:43PM (#29352819)
But this gives very short set of possible function names (up to 20 characters length (?), more is not adequate for development). And even with this parse_str could be named something like "url_parse_query_params_from_str(str)".
Re:Ask HN: What can lead to misleading names of functions? on Friday November 26, 2021 @01:32PM (#29352727)
> I see tons of functions named update_data and get_state and add_items in the business logic sections

Maybe they're bounded by some clear context like class or module which serves specific set of tasks? Writing in well designed context MyPartOfSystem things like MyPartOfSystemUpdateData is another smellish side of naming I think. Or writing just long names that are used only in very short context (ex. variable "drivingLicenseCard" instead of "e", "entry" in "drivingLicenseCards.every((drivingLicenseCard) => drivingLicenseCard && checkSomehow(drivingLicenseCard))").

If they're not bound, then we have another source of spaghetti monster.

Ask HN: What can lead to misleading names of functions?

1) parse_str in PHP, which extracts query parameters from request URL. This can have simple explanation: this is old relict which was designed at earliest versions of PHP. And PHP back then was designed as web templating language, not general programming one. So this name wasn't much confusing in this context;2) What about functions like getOurCityTimezone() ? This functions seems to be...

( Read More... | 5 comments | 3 points | on HN )