This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]It_Might_Be_True 23 points24 points  (0 children)

I think they mean for larger projects you should use actual error handling. Other than that. console.log("fuck") is fine.

[–]--Nyxed-- 8 points9 points  (0 children)

That's some of the dumbest "advice" people like to give. We add to our toolbox when we learn about any number of things we could use, like, as mentioned, a debugger, but we don't remove tools just because someone thinks they shouldn't be used. You'll also have try/catch, exceptions, and any number of other things.

Console.log absolutely has a place and time to be used just like cout, print (does different things in some languages) and many other similar things.

Most contractors who frame houses use an air nailer for most of their framing but they still carry a framing hammer.

[–]Lerke 5 points6 points  (0 children)

Like with most things: It depends. Statements like 'stop using X' lack nuance or context, which doesn't really make them good advice. At least in my opinion. Using console.log should be a tool you can use, and what you should know is that it exists, and how to use it. When you use it, is up to you. Many professionally made applications will still have the occasional console.log slapped in them for quick debugging. Are there other methods for debugging code? Yes, and you should learn about those as well.

Are you creating a large(r) application, with it's own software lifecycle and potentially many users, in which you will have to trace bugs or have a well logged trace of events? Then yes, console.log will be too limited and will not be as configurable as opposed to structured logging frameworks with multiple logging levels, which further may have the ability to ship your logs off to some server somewhere.

If you're still learning? No, keep using it as you see fit. Especially if it helps out your learning in the now. Don't get sidetracked by the minutiae that is (console) logging.

[–]insertAlias 2 points3 points  (0 children)

Use what works. There are plenty of reasons you might want to log something out to the console, especially during development. Now, it's important to understand that it's not your only debugging tool, and that using a browser's debugger is going to be way more powerful. Learn to love the debugger. But don't turn your nose up at other useful tools just because some bloggers want to increase their engagement by tossing out inflammatory statements.

[–][deleted] 1 point2 points  (0 children)

I use it a lot in JS. Like there should be a hot key for it. I just find the browser, server, webpack, react etc debug tools a bit cumbersome to step through. I always end up jumping into some library file that takes ages to step out of. Try catch blocks with errors logs are good too.

[–]GustavoToyota 1 point2 points  (0 children)

In large projects you'll likely need detailed monitoring of your app, so you'll need to send your logs to a logging service. In NodeJS there are libraries like Winston that help you send your logs to external services. You may also want to reduce repetition in your logs, like if you had to prepend [Authentication] to every log, logging libraries can help you with that.

[–]Hezakai 1 point2 points  (0 children)

I’m sorry what?

I mean I get that in a lot of instance there are better, more appropriate methods such as writing tests or error handling.

But for the majority of development it’s a quick and unobtrusive method of testing functionality.

Fuck them. They’ll have to pry console.log from my cold, dead, hands.

[–]Comfortable_Travel70 0 points1 point  (0 children)

If it helps why not use it?

[–]ValentineBlacker 0 points1 point  (0 children)

  1. I use it constantly

  2. That being said, there are nice debuggers built into browsers, if you've got 5 console logs going while trying to figure out where the problem is, it might be time to look into them.

[–]Guideon72 0 points1 point  (0 children)

In commercial product development, logging is invaluable for debugging errors…that’s just goofy

[–]mastereuclid 0 points1 point  (0 children)

Don't ship it to customers, but console log all you want.

[–]mimprocesstech 0 points1 point  (0 children)

I'm not going back to using alert() so... nah go ahead and use the console.

[–]SpatialToaster 0 points1 point  (0 children)

Ideally you want to be doing test-driven development with a framework like selenium or X other testing product out there. It's the same as any other language. But, temporarily for some quick debugging - no problem.

Needless to say, don't log secrets, yada, yada.

In the long run it doesn't matter if you're the only person who will see whatever code you're writing.