NocturnalMorning@lemmy.world
on 25 Sep 2024 15:30
nextcollapse
Yeah, pretty much
MrJameGumb@lemmy.world
on 25 Sep 2024 16:10
nextcollapse
If you remove the 4th panel then this accurately describes call center customer service
Feathercrown@lemmy.world
on 25 Sep 2024 16:54
nextcollapse
I spent like 3 hours yesterday deduplicating two functions that were hundreds of lines long and nearly identical. I should probably learn how to use that git command that can diff two files on disk. Luckily I actually enjoy cleaning up code sometimes.
TrickDacy@lemmy.world
on 25 Sep 2024 16:58
nextcollapse
You can use a diff app directly such as meld which is free. Highly recommend.
pivot_root@lemmy.world
on 25 Sep 2024 17:12
nextcollapse
If you’re using a decent development system, you’ll have an executable called diff installed already :)
egrets@lemmy.world
on 25 Sep 2024 17:32
nextcollapse
VS Code’s diff tools are killer. Comparison is smarter than most, and you can edit either file as you go.
wizardbeard@lemmy.dbzer0.com
on 25 Sep 2024 17:43
collapse
And if you want to avoid the Microsoft stank, there’s VS Codium that has been de-Microsoft’d, like Chrome vs. Chromium.
FizzyOrange@programming.dev
on 25 Sep 2024 17:48
nextcollapse
If you use VSCode, open both files and then ctrl-shift-P “Compare active file with …”
You’re welcome.
Feathercrown@lemmy.world
on 25 Sep 2024 18:19
collapse
Thank you! I love VS Code
expr@programming.dev
on 25 Sep 2024 18:59
nextcollapse
Dunno what OS’s it supports besides Windows but I use Kdiff for random comparisons regularly, I think it works pretty well untill you get to much larger files (20+ MB slows down a lot). The huge file wasn’t code but needed to check output changes for those curious.
I constantly check git comparison with previous versions to see what changed to break things in a build though. Didn’t know there was a way to diff any files in git,should probably just learn to use that one.
You don’t have to save it to a file but I often do.
FizzyOrange@programming.dev
on 25 Sep 2024 17:02
nextcollapse
…for people who refuse to use static types.
blaue_Fledermaus@mstdn.io
on 25 Sep 2024 17:10
collapse
Static types are great, but not exactly what would have helped here, any decent language or at least a linter should catch the use of a not declared identifier.
FizzyOrange@programming.dev
on 25 Sep 2024 17:33
collapse
def foo(x):
return x.whatevr
No linter is going to catch that.
BrianTheeBiscuiteer@lemmy.world
on 25 Sep 2024 18:20
nextcollapse
How would you make it non-awful, without specifying static types?
I guess, a unit test would catch it, but needing 100% test coverage to catch typos isn’t exactly great…
el_abuelo@programming.dev
on 25 Sep 2024 20:59
nextcollapse
I use a spell checker in my IDE. It would catch this.
Backlog3231@reddthat.com
on 27 Sep 2024 01:58
collapse
I would do
class MyClass:
def __init__(self, value):
self._whatever = value
@property
def whatever(self):
return self._whatever
Personally, I would type hint all of that but I’m just showing how you can do it without types. Your linter should be smart enough to say “hey dumbass did you mean this other thing”? Also since we didn’t create a setter you can’t arbitrarily overwrite the value of whatever so thats neat.
And I’ll just say before I post that I’m on mobile and I’m sorry if the formatting is fucked. I’m not going to fix it.
FizzyOrange@programming.dev
on 25 Sep 2024 19:15
nextcollapse
What’s awful about this example? The only thing I do is access an object member. Does your code not do that??
BrianTheeBiscuiteer@lemmy.world
on 25 Sep 2024 19:19
collapse
What’s the purpose of foo? Why an ambiguous single character variable? What if the property was there but the value was null? Why not use (assuming JS) optional chaining?
Sorry, read too fast the first time. It’s more likely Python. I also don’t know Python well enough to give recommendations on that.
FizzyOrange@programming.dev
on 25 Sep 2024 21:38
nextcollapse
It’s an example to demonstrate that linters cannot reliably detect variable name typos - you need static types. None of the stuff you mentioned is relevant.
The typo in your example is also undetectable by linters. I think you’re missing the point.
calcopiritus@lemmy.world
on 26 Sep 2024 05:56
collapse
Lmao, and they say dynamic typing is supposed to speed up the developer.
calcopiritus@lemmy.world
on 26 Sep 2024 05:53
collapse
This is literally a getter function. How is a getter awful code? It’s the simplest function there is. The only function simpler than that is returning the input itself.
BrianTheeBiscuiteer@lemmy.world
on 26 Sep 2024 16:11
collapse
How does “foo” mean “get”? Half the battle of writing correct code is writing code that’s easy to interpret. Do you always look at the guts of every function you’re about to use?
calcopiritus@lemmy.world
on 26 Sep 2024 19:45
collapse
It’s a one line function in an example. It’s a getter.
ripcord@lemmy.world
on 25 Sep 2024 18:45
nextcollapse
Not with an example that simple and poor, no.
If you have done the minimum and at least set a type hint, or if your ide is smart enough to check what calls the function and what it passes, then it’ll be flagged.
Strykker@programming.dev
on 25 Sep 2024 18:53
nextcollapse
It’s python, just use type hinting already and your linter will catch that.
Also some winters can look at the use of food and see the type being passed in.
I was very confused, why we’re suddenly talking about rationing food during winter. 🙃
Strykker@programming.dev
on 25 Sep 2024 19:56
collapse
Holy crap that’s wild, new phones autocorrect is out to get me
FizzyOrange@programming.dev
on 25 Sep 2024 19:15
collapse
Yes you can use static type hinting and the static type checker (Mypy or Pyright) will catch that. Linters (Pylint) won’t.
UndercoverUlrikHD@programming.dev
on 25 Sep 2024 22:48
collapse
class MyClass:
def __init__(self, x: int):
self.whatever: int = x
def foo(x: MyClass) -> int:
return x.whatevr
Any decent IDE would give you an error for unresolved attribute. Likewise it would warn you of type error if the type of x.whatever didn’t match the return type of foo()
Starbuncle@lemmy.ca
on 25 Sep 2024 22:54
nextcollapse
You’re both right. It’s possible to write code that gets linted well in Python, yes, but you’re often not working with just your code. If a library doesn’t use typing properly, not a lot to be done without a ton more effort.
calcopiritus@lemmy.world
on 26 Sep 2024 05:50
nextcollapse
Python doesn’t check the types of function headers though. They’re only hints for the programmer.
UndercoverUlrikHD@programming.dev
on 26 Sep 2024 06:22
collapse
OP suggested that linters for python won’t catch attribute errors, which they 100% will if you use type hints, as you should.
What happens at runtime is really relevant in this case.
FizzyOrange@programming.dev
on 26 Sep 2024 20:43
collapse
Linters 100% won’t. A static type checker is not a linter.
UndercoverUlrikHD@programming.dev
on 26 Sep 2024 21:21
collapse
I don’t want to get into an Internet argument over pedantry. Linter is often used as a catch-all term for static analysis tools.
Wikipedia defines it as
Lint is the computer science term for a static code analysis tool used to flag programming errors, bugs, stylistic errors and suspicious constructs.
Catching type errors and attribute errors would fit under this description, if you use a different, more precise definition at your workplace, cool, then we just have different definitions for it. The point is that your IDE should automatically detect the errors regardless of what you call it.
FizzyOrange@programming.dev
on 26 Sep 2024 21:48
collapse
In common usage a linter detects code that is legal but likely a mistake, or code that doesn’t follow best practice.
Although static type checkers do fit in that definition, that definition is overly broad and they would not be called a “linter”.
Here is how static type checkers describe themselves:
Pyright is a full-featured, standards-based static type checker for Python.
Mypy is a static type checker for Python.
TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.
Sorbet is a fast, powerful type checker designed for Ruby.
Here is how linters describe themselves:
Pylint is a static code analyser for Python 2 or 3. … Pylint analyses your code without actually running it. It checks for errors, enforces a coding standard, looks for code smells, and can make suggestions about how the code could be refactored.
(Ok I guess it’s a bit redundant for Pylint to say it is a linter.)
Eslint: The pluggable linting utility for JavaScript and JSX
Clippy: A collection of lints to catch common mistakes and improve your Rust code.
Ruff: An extremely fast Python linter and code formatter, written in Rust.
You get the idea… Linters are heuristic and advisory. Quite different to static type checking.
FizzyOrange@programming.dev
on 26 Sep 2024 06:23
collapse
Yes because you used static type annotations. This thread was about code that doesn’t use static types (or static type annotations/hints).
Nope, don’t need to. WebStorm can even detect nonexistent attributes for objects whose format the back-end decides, and tbh I’m not sure what sort of sorcery it uses.
FizzyOrange@programming.dev
on 27 Sep 2024 11:35
collapse
Yeah IntelliJ does amazingly without type annotations but even it can’t do everything. E.g. if you’re using libraries without type annotations, or if you don’t call functions with every possible type (is your testing that good? No.)
Static types have other benefits anyway so you should use them even if everyone in your team uses IntelliJ.
Yeah, our company has been meaning to transition to them for a while. I started saying Jsdoc comments but people complained about the pollution. Then I said fine, we’ll do TypeScript one day instead.
That one day has yet to come. I don’t actually get to decide much at this company, after all. Aah, technical debt.
FizzyOrange@programming.dev
on 27 Sep 2024 12:14
collapse
I’ve never done it but apparently you can actually gradually transition to Typescript one file at a time by renaming them from .js to .ts. Might help a bit. Good luck anyway!
JoeKrogan@lemmy.world
on 25 Sep 2024 18:26
nextcollapse
The problem is the client 🤣
RestrictedAccount@lemmy.world
on 27 Sep 2024 12:27
collapse
Airline mechanics used to record reported problems they couldn’t find as:
Joystick actuator error
FreshLight@sh.itjust.works
on 25 Sep 2024 18:38
nextcollapse
Hey, that’s me! Minus the last panel :)
JakenVeina@lemm.ee
on 25 Sep 2024 19:19
nextcollapse
I appreciate the “carrot with a bit out of it” icon.
vala@lemmy.world
on 25 Sep 2024 20:11
nextcollapse
Use spell check in your code editor and never experience this again.
MonkderVierte@lemmy.ml
on 26 Sep 2024 10:25
collapse
Spellcheck? My editor proposes known words after 3 characters.
bricked@discuss.tchncs.de
on 26 Sep 2024 05:56
nextcollapse
This literally happened to me yesterday, but with filenames. I was failing to configure a program until an hour later I found out that I mispelled the config file as colors.ini instead of color.ini.
Kissaki@programming.dev
on 26 Sep 2024 06:39
collapse
I like that even here on Lemmy, with inline code format, colors.ini is not being colored but color.ini is. Great symbolism for your issue.
Clinicallydepressedpoochie@lemmy.world
on 26 Sep 2024 20:23
nextcollapse
The older I get the more impatient I get with stupid tasks that take longer then they should. I simplify my life by focusing on the task ahead of me. Knowing these small tasks compound into the final goal.
So when I am looking through 17 different folders for a file I can’t remember what I saved it as and I’m sorting by date and opening things frantically…
‘it’s been 20 fucking minutes, should I just take the rest of the day to organize my shit? But if I get this fucking thing done I can setup a meeting on this today and fit it in this week before Juan goes on vacation and I have to wait two weeks to place an order that will take 6 months to deliver.’
‘Fuuuuuuuuu where the fuck is this file, I’ll just start from scratch and I’ll be done by 2pm just in time for it to go on the calender so everyone can seee. Or maybe i just look another 15 minutes wheeerreeeee the fuckkkk did I save this?!?!’
‘Bullshit bullshit bullshit!"
Google: how to find file.
Google: how to find file just working on.
Google: how to find excel file by date, most recent.
Google: file not in recent, why come?
Google: did I dream this nightmare wake me, wake me, wake me.’
Backlog3231@reddthat.com
on 27 Sep 2024 00:43
collapse
find -iname ‘*part*’ has saved my butt countless times.
find a . | grep part if you’re feeling stupid and lazy!
buddascrayon@lemmy.world
on 26 Sep 2024 21:53
nextcollapse
This is me but not with programming, just in my interactions with other people.
unemployedclaquer@sopuli.xyz
on 27 Sep 2024 06:21
collapse
it feels like it should it work to just poke a stranger when you want to talk to them
couch1potato@lemmy.dbzer0.com
on 27 Sep 2024 12:38
collapse
it works
grudan@programming.dev
on 26 Sep 2024 23:03
nextcollapse
I spent such a long time the other day trying to figure out why I couldn’t access an application I wrote and served on a home server from my reverse proxy. Next day I take a look at the DNS record I setup again, CNAMEd to the host server instead of the reverse proxy server. Felt dumb.
Backlog3231@reddthat.com
on 27 Sep 2024 00:41
nextcollapse
Programming has its highs and lows. Yesterday I spent four hours trying to write a script that honestly probably won’t even be useful to anyone.
Today I felt like a god because I built a recursive query to pull some ridiculously obscure data from our database.
Tomorrow I’ll probably delete a table in prod or something.
You win some, you lose some!
mahmoudajawad@mastodon.online
on 27 Sep 2024 01:50
nextcollapse
@gyanendraknojiya my fellow developer somehow had a zero-width space in the endpoint name he was making request against, and it drove him crazy for almost an hour.
ZILtoid1991@lemmy.world
on 27 Sep 2024 06:07
nextcollapse
If you thought misspelling a variable was bad, then get ready for misreading documentation of OS API, then not realize why your implementation doesn’t work for a quite a long time.
DumbAceDragon@sh.itjust.works
on 27 Sep 2024 13:51
collapse
What compiler are you using that wouldn’t tell you right away?
threaded - newest
I’m in this picture, and I don’t like it.
I didn’t sign a release!
No I’m Spartacus.
Yeah, pretty much
If you remove the 4th panel then this accurately describes call center customer service
I spent like 3 hours yesterday deduplicating two functions that were hundreds of lines long and nearly identical. I should probably learn how to use that git command that can diff two files on disk. Luckily I actually enjoy cleaning up code sometimes.
You can use a diff app directly such as meld which is free. Highly recommend.
If you’re using a decent development system, you’ll have an executable called
diff
installed already :)VS Code’s diff tools are killer. Comparison is smarter than most, and you can edit either file as you go.
And if you want to avoid the Microsoft stank, there’s VS Codium that has been de-Microsoft’d, like Chrome vs. Chromium.
If you use VSCode, open both files and then ctrl-shift-P “Compare active file with …”
You’re welcome.
Thank you! I love VS Code
That’s what the
diff
tool is for.Dunno what OS’s it supports besides Windows but I use Kdiff for random comparisons regularly, I think it works pretty well untill you get to much larger files (20+ MB slows down a lot). The huge file wasn’t code but needed to check output changes for those curious.
I constantly check git comparison with previous versions to see what changed to break things in a build though. Didn’t know there was a way to diff any files in git,should probably just learn to use that one.
Git uses the
diff
binary under the hood (unless you configure it to use something else).You can invoke that directly with
diff file_a.txt file_b.txt
.git diff —no-index before.json after.json > showmethegoods.diff
You don’t have to save it to a file but I often do.
…for people who refuse to use static types.
Static types are great, but not exactly what would have helped here, any decent language or at least a linter should catch the use of a not declared identifier.
No linter is going to catch that.
Always love seeing the trope:
How would you make it non-awful, without specifying static types?
I guess, a unit test would catch it, but needing 100% test coverage to catch typos isn’t exactly great…
I use a spell checker in my IDE. It would catch this.
I would do
Personally, I would type hint all of that but I’m just showing how you can do it without types. Your linter should be smart enough to say “hey dumbass did you mean this other thing”? Also since we didn’t create a setter you can’t arbitrarily overwrite the value of whatever so thats neat.
And I’ll just say before I post that I’m on mobile and I’m sorry if the formatting is fucked. I’m not going to fix it.
What’s awful about this example? The only thing I do is access an object member. Does your code not do that??
What’s the purpose of foo? Why an ambiguous single character variable? What if the property was there but the value was null? Why not use (assuming JS) optional chaining?
I’d approach it more like this:
Sorry, read too fast the first time. It’s more likely Python. I also don’t know Python well enough to give recommendations on that.
It’s an example to demonstrate that linters cannot reliably detect variable name typos - you need static types. None of the stuff you mentioned is relevant.
The typo in your example is also undetectable by linters. I think you’re missing the point.
Lmao, and they say dynamic typing is supposed to speed up the developer.
This is literally a getter function. How is a getter awful code? It’s the simplest function there is. The only function simpler than that is returning the input itself.
How does “foo” mean “get”? Half the battle of writing correct code is writing code that’s easy to interpret. Do you always look at the guts of every function you’re about to use?
It’s a one line function in an example. It’s a getter.
Not with an example that simple and poor, no.
If you have done the minimum and at least set a type hint, or if your ide is smart enough to check what calls the function and what it passes, then it’ll be flagged.
It’s python, just use type hinting already and your linter will catch that.
Also some winters can look at the use of food and see the type being passed in.
Autocorrect got you pretty bad, there.
I was very confused, why we’re suddenly talking about rationing food during winter. 🙃
Holy crap that’s wild, new phones autocorrect is out to get me
Yes you can use static type hinting and the static type checker (Mypy or Pyright) will catch that. Linters (Pylint) won’t.
Any decent IDE would give you an error for unresolved attribute. Likewise it would warn you of type error if the type of
x.whatever
didn’t match the return type offoo()
You’re both right. It’s possible to write code that gets linted well in Python, yes, but you’re often not working with just your code. If a library doesn’t use typing properly, not a lot to be done without a ton more effort.
Python doesn’t check the types of function headers though. They’re only hints for the programmer.
OP suggested that linters for python won’t catch attribute errors, which they 100% will if you use type hints, as you should.
What happens at runtime is really relevant in this case.
Linters 100% won’t. A static type checker is not a linter.
I don’t want to get into an Internet argument over pedantry. Linter is often used as a catch-all term for static analysis tools.
Wikipedia defines it as
Catching type errors and attribute errors would fit under this description, if you use a different, more precise definition at your workplace, cool, then we just have different definitions for it. The point is that your IDE should automatically detect the errors regardless of what you call it.
In common usage a linter detects code that is legal but likely a mistake, or code that doesn’t follow best practice.
Although static type checkers do fit in that definition, that definition is overly broad and they would not be called a “linter”.
Here is how static type checkers describe themselves:
Here is how linters describe themselves:
(Ok I guess it’s a bit redundant for Pylint to say it is a linter.)
You get the idea… Linters are heuristic and advisory. Quite different to static type checking.
Yes because you used static type annotations. This thread was about code that doesn’t use static types (or static type annotations/hints).
Nope, don’t need to. WebStorm can even detect nonexistent attributes for objects whose format the back-end decides, and tbh I’m not sure what sort of sorcery it uses.
Yeah IntelliJ does amazingly without type annotations but even it can’t do everything. E.g. if you’re using libraries without type annotations, or if you don’t call functions with every possible type (is your testing that good? No.)
Static types have other benefits anyway so you should use them even if everyone in your team uses IntelliJ.
Yeah, our company has been meaning to transition to them for a while. I started saying Jsdoc comments but people complained about the pollution. Then I said fine, we’ll do TypeScript one day instead.
That one day has yet to come. I don’t actually get to decide much at this company, after all. Aah, technical debt.
I’ve never done it but apparently you can actually gradually transition to Typescript one file at a time by renaming them from
.js
to.ts
. Might help a bit. Good luck anyway!The problem is the client 🤣
Airline mechanics used to record reported problems they couldn’t find as:
Joystick actuator error
Hey, that’s me! Minus the last panel :)
I appreciate the “carrot with a bit out of it” icon.
Use spell check in your code editor and never experience this again.
Spellcheck? My editor proposes known words after 3 characters.
This literally happened to me yesterday, but with filenames. I was failing to configure a program until an hour later I found out that I mispelled the config file as
colors.ini
instead ofcolor.ini
.I like that even here on Lemmy, with inline code format,
colors.ini
is not being colored butcolor.ini
is. Great symbolism for your issue.The older I get the more impatient I get with stupid tasks that take longer then they should. I simplify my life by focusing on the task ahead of me. Knowing these small tasks compound into the final goal.
So when I am looking through 17 different folders for a file I can’t remember what I saved it as and I’m sorting by date and opening things frantically…
‘it’s been 20 fucking minutes, should I just take the rest of the day to organize my shit? But if I get this fucking thing done I can setup a meeting on this today and fit it in this week before Juan goes on vacation and I have to wait two weeks to place an order that will take 6 months to deliver.’
‘Fuuuuuuuuu where the fuck is this file, I’ll just start from scratch and I’ll be done by 2pm just in time for it to go on the calender so everyone can seee. Or maybe i just look another 15 minutes wheeerreeeee the fuckkkk did I save this?!?!’
‘Bullshit bullshit bullshit!"
Google: how to find file.
Google: how to find file just working on.
Google: how to find excel file by date, most recent.
Google: file not in recent, why come?
Google: did I dream this nightmare wake me, wake me, wake me.’
find -iname ‘*part*’
has saved my butt countless times.find a . | grep part
if you’re feeling stupid and lazy!This is me but not with programming, just in my interactions with other people.
it feels like it should it work to just poke a stranger when you want to talk to them
it works
I spent such a long time the other day trying to figure out why I couldn’t access an application I wrote and served on a home server from my reverse proxy. Next day I take a look at the DNS record I setup again, CNAMEd to the host server instead of the reverse proxy server. Felt dumb.
Programming has its highs and lows. Yesterday I spent four hours trying to write a script that honestly probably won’t even be useful to anyone.
Today I felt like a god because I built a recursive query to pull some ridiculously obscure data from our database.
Tomorrow I’ll probably delete a table in prod or something.
You win some, you lose some!
@gyanendraknojiya my fellow developer somehow had a zero-width space in the endpoint name he was making request against, and it drove him crazy for almost an hour.
If you thought misspelling a variable was bad, then get ready for misreading documentation of OS API, then not realize why your implementation doesn’t work for a quite a long time.
What compiler are you using that wouldn’t tell you right away?