News for hackers. Stuff that matters.
Re:Console.table() by pjmlp on Thursday June 14, 2018 @04:20AM (#17310216)
Only for those developers that insist in not using IDEs.

Common Lisp and Smalltalk environments have something like console.table since its early days.

Xerox even went to the trouble of adding similar capabilities to the Mesa/Cedar enviroment, because they thought they should cater to their Interlisp-D and Smalltalk developers.

Java and .NET even allow to provide metadata so that debuggers know what is the best way to render the data in debug view.

Visual Studio allows similar capabilities for C++ via data visualizers.

Now if you insist in vim and Emacs, there is printf.

Re:Console.table() by megaman22 on Thursday June 14, 2018 @04:31AM (#17310254)
I'm amazed sometimes at what people are able to accomplish banging rocks together and doing things the hard way.

Me, I'm lazy, so I lean on my tools to make my life easy. And there's some fantastic tooling out there; the biggest problem is usually discovering that a helpful feature exists and how to use it effectively.

Re:Console.table() by pjmlp on Thursday June 14, 2018 @04:57AM (#17310358)
Yes, that is why Visual Studio team started doing talks about how to use the debugger.

They started to realize that there were many developers doing feature requests for stuff Visual Studio already supports.

Re:Console.table() by hawski on Thursday June 14, 2018 @07:45AM (#17310898)
Do you know how to record all backtraces of all threads and child processes with the VS debugger? Just curious. I did it lately with gdb [0], but with a bit guerrilla method. It was my try at localizing the origins of dreadlocks. I would appreciate pointers for something better for dreadlocks, but the original question still stands.

I understand that what I did would be a bit close to a poor man's reversible debugger.

[0] https://gist.github.com/hadrianw/5b8d33a4b353c49e7dbd6eb55f8...

Re:Console.table() by pjmlp on Thursday June 14, 2018 @08:02AM (#17310974)
Re:Console.table() by jupp0r on Thursday June 14, 2018 @09:43AM (#17311602)

   Now if you insist in vim and Emacs, there is printf.
That's just plain wrong. GDB for example has had pretty printers for STL data structures for many years. Those operate on the underlying structure of the data types and you can write printers for your own data types pretty easily (gdb uses python for these).

Apart from that, there is structured hierarchical logging, which seems to be on the way of becoming an industry standard and is considered best practice in some ecosystems (golang comes to mind)

Re:Console.table() by mort96 on Thursday June 14, 2018 @04:27AM (#17310240)
It has little to do with IDEs and everything to do with debuggers. When writing code in emacs or vim, as long as you compile with -g and run the binary with gen, you get the features you're talking about.
Re:Console.table() by pjmlp on Thursday June 14, 2018 @04:50AM (#17310328)
Unless you are speaking about something like DDD, not really.

Also it has to do with IDE, because in an IDE there is two way communication between both tools, like the ability to do edit-and-continue.

Re:Console.table() by mort96 on Thursday June 14, 2018 @08:04AM (#17310983)
Look at this: https://news.ycombinator.com/item?id=17310418

It's not quite as fancy as an IDE, but it's a lot more than printf.

Re:Console.table() by earenndil on Saturday June 16, 2018 @03:24AM (#17326374)
What's gen? It's not very googlable ('gen debugger' gives nothing relevant), and asking my package manager for a package providing 'gen' just gives some game.
Re:Console.table() by mort96 on Tuesday June 19, 2018 @01:50PM (#17348801)
Oh wow, I didn't notice that. I wrote gdb, but my phone autoincorrected it to gen.
Re:Console.table() by oblio on Thursday June 14, 2018 @05:16AM (#17310418)
Could you show a screenshot?
Re:Console.table() by mort96 on Thursday June 14, 2018 @06:39AM (#17310665)
Here's a recording of using GDB: https://s.mort.coffee/d/vid/gdb-demo.mp4

Here's a recording of using GDB's TUI mode: https://s.mort.coffee/d/vid/gdb-tui-demo.mp4

Note that I'm not a GDB pro, I just recently started trying to use it more instead of printf, so there are probably lots of stuff I didn't show off. (For example, I wish I'd shown the `bt` command to print stack traces).

Another thing that's worth noting is that with GDB, if your program crashed and generated a coredump, you can use GDB to look at how everything was when it crashed, just like if you were debugging a running program. This is extremely useful on for example embedded systems where you don't have GDB installed, or when the crash is hard to reproduce.

Re:Console.table() by oblio on Thursday June 14, 2018 @08:58AM (#17311277)
I know that GDB is powerful and scriptable and very useful in environment where you don't have anything else. But I'm sorry to say, what you showed wasn't very discoverable and the UI was faaar from amazing.

I don't know if you've tried it, but whenever you have a bit of time try Visual Studio's (or even Visual Studio Code's) debugger. They're among the best visual debuggers out there. Or IntelliJ's.

You see directly all the variables as you step through code, you can see array contents directly, they're super discoverable, etc.

It's such a shame that there's no glory (or money) to be had in designing CLI/TUIs. I also get the impression that it would be really hard to change things, OSS maintainers have a reputation for being very stubborn about workflow changes (sometimes for good reasons, sometimes not) :(

Re:Console.table() by camgunz on Thursday June 14, 2018 @12:10PM (#17312680)
GDB's main power is that it's scriptable. You can track down some pretty gnarly bugs with that. You don't necessarily need that capability for languages like JS, because there's far less danger of getting into serious trouble (stack corruption, etc.), so it's hard to appreciate. But yeah, discoverable it is not haha.
Re:Console.table() by pjmlp on Thursday June 14, 2018 @12:24PM (#17312800)
All major Java and .NET IDEs have debugging APIs as well.

As for the data visualizers, as mentioned, with Java and .NET I can do it with a bit of annotations and the debugger takes it from there.

Or in C++'s case when using Visual Studio, a bit of XML describing the metadata.

Re:Console.table() by camgunz on Thursday June 14, 2018 @03:37PM (#17314684)
Oh yeah, totally true. All I meant was GDB's power interface is scripting. I definitely think IDE debuggers are better.
Re:Console.table() by TickleSteve on Thursday June 14, 2018 @09:18AM (#17311421)
Thats just a textual display of the structures, not a different presentation (i.e. a graphical tree or table, allbeit in text mode).

BTW: In GDB, all commands have shortcuts i.e. 'b'=='break'. (Saves a lot of time).

Re:Console.table() by TeMPOraL on Thursday June 14, 2018 @12:56PM (#17313118)
> Visual Studio allows similar capabilities for C++ via data visualizers.

No reason this couldn't be possible for Emacs, I guess nobody bothered. In particular, Common Lisp with SLIME already makes use of "presentations" in REPL, which nicely combine CL's print-object output with inspector/debugger capabilities.

Ultimately, no one limits you to printing out simple text. In various Lisp software I wrote, I ended up displaying profiling info inline in REPL, like this:

          CHARTED-LET*                  
                              0    9.249
                              ˫--------˧
              SOME-VAR: 0.006 |
             OTHER-VAR: 0.004 |
      SOME-COMPUTATION: 2.036 |==.
             A-SUMMARY: 0.062 |
      DATA-FOR-A-CHART: 3.486 |====
  SOME-BIG-COMPUTATION: 9.249 |==========
       SOME-TREE-STUFF: 0.005 |
(EDIT: there were pretty Unicode characters in that output, but my browser / HN ate them. See https://github.com/tkych/cl-spark for how it should look like.)

(all it took was a simple macro on top of a sparkline lib). I dumped custom execution stats out-of-band into a HTML file that, with little bit of static JS, rendered explorable charts. I've sent data straight into new Emacs buffers for processing, with a help of this simple macro:

https://gist.github.com/TeMPOraL/8715c9dd9837e0b601d1cdce059...

(can be trivially modified to make the new buffer automatically assume a given major-mode).

Point is, you don't have to limit yourself to simple, uninterpreted printfs. Write your own debugging tools! And while I'm not up to date with C#, most other languages and IDEs I've seen don't move beyond dumb printfs. Java definitely doesn't (hint: Grep Console is a very useful plugin to IntelliJ and Eclipse). And this Console.table() is just a visual gimmick. I'm actually disappointed that with all the capabilities for interactive HTML rendering, that's the best the Web standardized on so far.

Re:Console.table() by pjmlp on Friday June 15, 2018 @01:45AM (#17317754)
When I think about Common Lisp debugging capabilities usually what comes to my mind is Allegro, Lisp Works, MCL, CCL, not SLIME in text mode single window.
Re:Console.table() by TeMPOraL on Friday June 15, 2018 @04:05AM (#17318228)
Sure, but a lot of CL development these days is done with SBCL and SLIME - Allegro and LispWorks are expensive, and whatever cool stuff CCL has would require me to buy a Mac.
Re:Console.table() by ultim8k on Thursday June 14, 2018 @05:25AM (#17310445)
I will start using IDEs again once they get instant, mouse-free, java-crawltime-env free and get easily extensible like most modern editors are.
Re:Console.table() by pjmlp on Thursday June 14, 2018 @05:33AM (#17310459)
Can you please provide a screenshot of something like Console.table() for a tree data structure on your extensible modern editor?
Re:Console.table() by gkya on Thursday June 14, 2018 @07:44AM (#17310891)
This would be fairly easy to build in Emacs for almost any language, but I can't see how this is so useful. Furthermore, if working with Org mode source blocks, it can render structured data as tables upon evaluation. Say you have this block:

  #+BEGIN_SRC elisp
  (list (list 'col1 'col2) (list 1 2))
  #+END_SRC
(I don't use quote syntax to not confuse non-lispers) Hitting C-c C-c on it produces the following block just below it:

  #+RESULTS:
  | col1 | col2 |
  |    1 |    2 |
With Org source blocks you can have a literate program even using multiple languages and still communicating easily between source code blocks and both generated and static tables. It can easily be intermixed with formatted text and exported to a suite of various formats, including plain text source code (so-called "tangled source").

Edit: just for the sake of it, another example, this one in Python:

  #+BEGIN_SRC python
  return [[x for x in range(1,5)],
          [chr(y) for y in range(ord('a'),ord('e'))]]
  #+END_SRC
  
  #+RESULTS:
  | 1 | 2 | 3 | 4 |
  | a | b | c | d |
Re:Console.table() by oblio on Thursday June 14, 2018 @09:48AM (#17311633)
I don't get why in this day and age we can't have proper text mode interfaces.

Freaking IBM had box drawing characters in freaking 1985, how hard is it to have them in 2018? https://www.ascii-codes.com/

See this:

  ┌─┬┐  
  │ ││  
  ├─┼┤  
  └─┴┘
vs the crappy table.
Re:Console.table() by TeMPOraL on Thursday June 14, 2018 @12:30PM (#17312861)

  | Hello | Planet | Earth |
  |-------+--------+-------|
  | foo   |      4 |    88 |
  | bar   |    265 |   123 |
  |-------+--------+-------|
  | sum   |    269 |   211 |
This org table looks clean enough to me.

The disadvantage of using box drawing characters is that they do not always align nicely - depending on the font, renderer, and couple other things. You can't go wrong with basic ASCII and a fixed-width display.

Re:Console.table() by gowld on Thursday June 14, 2018 @01:55PM (#17313732)
The point of Org mode is that you can type the table.

How do you type ┌─ ?

It's easier to use a font that renders "regular" keyboard characters as borders, akin to https://github.com/tonsky/FiraCode

Re:Console.table() by pjmlp on Thursday June 14, 2018 @12:16PM (#17312736)
Even GDB TUI comes short to what Turbo products with their Turbo Vision based UI were capable of on MS-DOS.
Re:Console.table() by gkya on Thursday June 14, 2018 @10:55AM (#17312173)
It's misaligned on my screen. Still, it would not be too hard to hack that in to Org.
Re:Console.table() by rkeene2 on Thursday June 14, 2018 @10:53AM (#17312158)
Do you believe this adds some kind of clarity to the data ?
Re:Console.table() by oblio on Thursday June 14, 2018 @11:58AM (#17312602)
Yes. There's a reason no one (except for hardcore geeks) uses ASCII tables.
Re:Console.table() by rkeene2 on Friday June 15, 2018 @10:19AM (#17319933)
Do you know what that reason is, and can you elucidate me ?
Re:Console.table() by oblio on Friday June 15, 2018 @11:26AM (#17320396)
They don't look nice...

Beauty is in the eye of the beholder, true, but the majority of the beholders want a table to actually look like a table. If you give me pen and paper, I'm not going to draw weird half lines around the table, I'm going to draw the table first, line fully drawn everywhere and then add the content.