From: Rodrigo Morales <moralesrodrigo1100@gmail.com>
To: Greg Minshall <minshall@umich.edu>
Cc: emacs-orgmode@gnu.org
Subject: Re: How do you name your code blocks?
Date: Tue, 16 Feb 2021 20:21:05 -0500 [thread overview]
Message-ID: <87wnv7lcam.fsf@gmail.com> (raw)
In-Reply-To: <1417212.1613451192@apollo2.minshall.org>
Greg Minshall <minshall@umich.edu> writes:
> i guess part of the answer depends on why you are naming your code
> blocks.
I was asking because in my notes in Org Mode, I am used to create
subheadings for each question I have. Here's an example:
Let's say that in my notes on Python, I have the following content
#+begin_src org
,* DONE How to get the number of lines in a file?
- State "DONE" from [2021-02-16 Tue 20:02]
,#+NAME: create-file
,#+begin_src dash :results silent
cat << EOF > main.txt
first
second
third
EOF
,#+end_src
,#+begin_src python
print(len(open('main.txt').readlines()))o3
,#+end_src
,#+RESULTS:
,#+begin_example
3
,#+end_example
,* DONE How to print most repeated word in a file?
- State "DONE" from [2021-02-16 Tue 20:02]
,#+NAME: create-file
,#+begin_src dash :results silent
cat << EOF > main.txt
fizz fizz fizz
buzz buzz buzz buzz
foo
bar bar
EOF
,#+end_src
,#+begin_src python
import re
from collections import Counter
with open('main.txt') as f:
passage = f.read()
words = re.findall(r'\w+', passage)
word_counts = Counter(words)
print(word_counts.most_common(1))
,#+end_src
,#+RESULTS:
,#+begin_example
[('buzz', 4)]
,#+end_example
#+end_src
As you can see above, there are two code blocks which creates two text
files so that a Python script can then process it. Both of them create
a text file, that's why I have used =create-file= as the name of those
code block. I could have used very long names but I don't find
comfortable myself doing that since it adds extra effort to think in a
name for such simple code blocks (see below an example of the approach
of using long names).
#+begin_src org
,* DONE How to get the number of lines in a file?
,#+NAME: create-file-for-counting-lines
,#+begin_src dash :results silent
cat << EOF > main.txt
first
second
third
EOF
,#+end_src
,* DONE How to print most repeated word in a file?
,#+NAME: create-file-for-finding-most-repeated-word
,#+begin_src dash :results silent
cat << EOF > main.txt
fizz fizz fizz
buzz buzz buzz buzz
foo
bar bar
EOF
,#+end_src
#+end_src
--
Rodrigo Morales.
IRC: rdrg109 (freenode)
next prev parent reply other threads:[~2021-02-17 1:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-15 19:18 How do you name your code blocks? Rodrigo Morales
2021-02-16 4:53 ` Greg Minshall
2021-02-17 1:21 ` Rodrigo Morales [this message]
2021-02-16 12:03 ` Eric S Fraga
2021-02-17 1:27 ` Rodrigo Morales
2021-02-17 6:56 ` Greg Minshall
2021-02-17 20:31 ` Rodrigo Morales
2021-02-17 1:58 ` Kevin M. Stout
2021-02-17 9:57 ` Eric S Fraga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wnv7lcam.fsf@gmail.com \
--to=moralesrodrigo1100@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=minshall@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).