2024-01-22 Forthic Office Hours

Resources

 Date

Jan 22, 2024

 Questions

Q: At LinkedIn, I am trying to use trino from v3 but gdoc is commented in v3. Any reason for that?

At LinkedIn, the gdoc module in v3 was intended to be rewritten so that it was more flexible. The original gdoc module was written for a specific use case and had a lot of code to support that. I had wanted the v3 version to be redesigned to be more universal and provide 1-1 mappings to the underlying Google Doc API.

It’s possible to copy the v2 version of the gdoc module over into v3, but this requires doing some Python coding. You might be able to get this running locally, but to update ratchet would require software engineering support.

Q: How can we read query string params?

In LinkedIn’s version of Forthic, the query parameters are pushed onto the stack immediately before the MAIN-PAGE word is called. If you store them in a variable you can use them as you might any Forthic record. For instance:

["qparams"] VARIABLES : MAIN-PAGE (qparams !) <your definition for this>; # If the query param string were "project=alpha&user=rjose", then qparams @ 'project' REC@ # "alpha" qparams @ 'user' REC@ # "rjose"

Q: Debugging is a challenge. Any tips would be helpful

I am working on some tools to help make debugging easier, but for now here’s how I debug Forthic (and most anything)

Scientific Method + Binary Search

The best way to proceed is using the scientific method combined with binary search. By that, I mean you should try to think of how to divide where the error is in half each time. For instance:

  • Is the problem in the pulling of the data or the processing of the data?

  • Is it on the client or the server?

  • Is it in the storing of the data or the reading of the data?

  • Is it in this half of the code or the other half of the code?

Ask a question that divides your problem space and then come up with a hypothesis. Create an experiment to test your hypothesis. Ideally your experiment will rule out half of your search space. Continue until your hypothesis is correct

Use .s to see the top of the stack

The .s word will show you the top of the stack and drop you into the Python debugger. This is a quick way to see the state of your code.

Use the cache module to write larger amounts of data in a readable format

Sometimes the top of the stack has a lot of data in it. In this case, it’s a lot easier to write this to the cache (where it’s nicely formatted) and examine it in your editor. Here’s an example of how you might do this:

["cache"] USE-MODULES # This will store the results of your code in the `result` key of the cache <your-code-with-some-result> "result" cache.CACHE! # If you're running locally, you can view the `.cache` file in your app's directory

Project your data down to smaller set

This can be helpful in several ways. One is a way of doing binary search. If you have an array of data, and you suspect that the problem is in some of the data but not all, you can split your data in half and figure out where the problem is. For instance:

["my_array"] VARIABLES <your-code-that-produces-an-array> my_array ! : my_array-LENGTH my_array @ LENGTH; : my_array-FIRST-HALF my_array @ my_array-LENGTH 2 / TAKE; : my_array-SECOND-HALF my_array @ my_array-LENGTH 2 / DROP; # You can repeatedly halve the data this way

The second way this helps is allowing you to focus on a particular case so you can follow it through. This can save both execution time (because you’re pulling and processing less data) as well as your own time because you’re looking at less data. If you have an array of data, you can get a one-element array using 1 TAKE.

Q: How can I make sure a user adds an attachment to an intake form if they have one?

If the attachment is not a required field, but you want to encourage them to add one anyway, one option is to update the Description cell for the attachment field in your Google Sheet to add a note letting people know that adding attachments helps speed up the resolution of the ticket.

Some intake forms have the option to add markdown or HTML directly to the form (check in the dropdown for the possible field types in your Google sheet). In these cases, you have more options for formatting the text.