Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6027931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:39:51+00:00 2026-05-23T04:39:51+00:00

I have now seen different elegant ways to layout code on this forum. As

  • 0

I have now seen different elegant ways to layout code on this forum.

As a beginner, I would like to have your advises on the best way to layout code like the one below.

It is ugly,not optimal, probably even stupid, but may the expert programmers pardon me, I use it as a “worst case scenario”.

The purpose for the novice I am is clarity.

rejection[disp_, fixationNOtoConsiderForDuration_, durationLimit_, 
 minDistance_] :=

With[{fakedata = consider[t4dataLAEH10, 9, disp, {17, 18, 11}]},

With[{num = 
 Flatten[Position[
   Take[fakedata[[All, 3]], fixationNOtoConsiderForDuration], 
   x_ /; (x > durationLimit)]]},

If[num =!= {},
With[{fakedata1 = Drop[fakedata[[All, {1, 2}]], Last@num]},
 With[{num1 =
    Flatten[Position[
      Table[     
       Sqrt[((fakedata1[[fixation1, 1]] - 
           centerX)^2 + (fakedata1[[fixation1, 2]] - 
           centerY)^2)],
       {fixation1, 1, Length@fakedata1}], 
      x_ /; (x < minDistance)]]},

  If[num1 =!= {},
   Delete[fakedata1[[All, {1, 2}]], List /@ num1], 
   fakedata[[All, {1, 2}]]]]],
With[{fakedata2 = fakedata[[All, {1, 2}]]},  
 With[{num2 =
    Flatten[Position[
      Table[       
       Sqrt[((fakedata2[[fixation2, 1]] - 
           centerX)^2 + (fakedata2[[fixation2, 2]] - 
           centerY)^2)],
       {fixation2, 1, Length@fakedata2}], 
      x_ /; (x < minDistance)]]},
  If[num2 =!= {},
   Delete[fakedata2[[All, {1, 2}]], List /@ num2], 
   fakedata[[All, {1, 2}]]]]]]]]

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:39:52+00:00Added an answer on May 23, 2026 at 4:39 am

    I chose to do a full rewrite because the original is simply too far from my own style for me to format it as I would my own code.

    I did not attempt to test this, so it is entirely possible something is broken, but I believe that most of it is correct.

    I use Text Cells to describe the syntax of my functions. I typically embed (* comments *) to explain the code, but if the explanations become very long, I move them to Text Cells as well.

    I included a comment explaining func1. It is not a very helpful comment, but it serves as an example.

    Here is an image of my notebook at 75% magnification:

    enter image description here

    Cell expression for copy&paste:

    Cell[CellGroupData[{Cell["Rewrite", "Subsection"],
    
    Cell[TextData[{
     StyleBox["distance", "Program"],
     "[{",
     StyleBox["x1",
      FontSlant->"Italic"],
     ", ",
     StyleBox["y1",
      FontSlant->"Italic"],
     "}] gives EuclideanDistance from {x1, y1} to global {centerX, \
    centerY}\n",
     StyleBox["distance", "Program"],
     "[{",
     StyleBox["x1",
      FontSlant->"Italic"],
     ", ",
     StyleBox["y1",
      FontSlant->"Italic"],
     "}, {",
     StyleBox["x2",
      FontSlant->"Italic"],
     ", ",
     StyleBox["y2",
      FontSlant->"Italic"],
     "}] gives EuclideanDistance from {x1, y1} to {x2, y2}"
    }], "Text"],
    
    Cell[BoxData[
     RowBox[{
      RowBox[{"distance", "[", 
       RowBox[{"a_", ",", 
        RowBox[{"b_:", 
         RowBox[{"Hold", "@", 
          RowBox[{"{", 
           RowBox[{"centerX", ",", "centerY"}], "}"}]}]}]}], "]"}], ":=", 
      RowBox[{"EuclideanDistance", "[", 
       RowBox[{"a", ",", 
        RowBox[{"ReleaseHold", "@", "b"}]}], "]"}]}]], "Input"],
    
    Cell[TextData[{
     StyleBox["rejection", "Program"],
     "[",
     StyleBox["disp, fixation, durationLimit, minDistance",
      FontSlant->"Italic"],
     "]\n\nfilters data from ",
     StyleBox["t4dataLAEH10", "Program"],
     " according to:\n\t",
     StyleBox["disp",
      FontSlant->"Italic"],
     " : (description of argument disp)\n\t",
     StyleBox["fixation",
      FontSlant->"Italic"],
     " : (description of argument fixation)\n\t",
     StyleBox["durationLimit",
      FontSlant->"Italic"],
     " : (description of durationLimit)\n\t",
     StyleBox["minDistance",
      FontSlant->"Italic"],
     " : (description of minDistance)"
    }], "Text"],
    
    Cell[BoxData[
     RowBox[{
      RowBox[{"rejection", "[", 
       RowBox[{
       "disp_", ",", "fixation_", ",", "durationLimit_", ",", 
        "minDistance_"}], "]"}], ":=", "\[IndentingNewLine]", 
      RowBox[{"Module", "[", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"fakedata", ",", "num", ",", "func1"}], "}"}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", " ", 
         RowBox[{"description", " ", "of", " ", "fakedata"}], " ", "*)"}],
         "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"fakedata", "=", 
          RowBox[{"consider", "[", 
           RowBox[{"t4dataLAEH10", ",", "9", ",", "disp", ",", 
            RowBox[{"{", 
             RowBox[{"17", ",", "18", ",", "11"}], "}"}]}], "]"}]}], ";", 
         "\[IndentingNewLine]", "\[IndentingNewLine]", 
         RowBox[{"(*", " ", 
          RowBox[{"description", " ", "of", " ", "num"}], " ", "*)"}], 
         "\[IndentingNewLine]", 
         RowBox[{"num", "=", 
          RowBox[{"Position", "[", 
           RowBox[{
            RowBox[{
             RowBox[{"fakedata", "\[LeftDoubleBracket]", 
              RowBox[{"All", ",", "3"}], "\[RightDoubleBracket]"}], "~", 
             "Take", "~", "fixation"}], ",", 
            RowBox[{"x_", "/;", 
             RowBox[{"x", ">", "durationLimit"}]}]}], "]"}]}], ";", 
         "\[IndentingNewLine]", "\[IndentingNewLine]", 
         RowBox[{"(*", " ", 
          RowBox[{
           RowBox[{"func1", ":", " ", 
            RowBox[{
            "Take", " ", "the", " ", "first", " ", "two", " ", "columns", 
             " ", "of", " ", "fakedata"}]}], ",", " ", 
           RowBox[{
            RowBox[{
             RowBox[{
             "and", " ", "drop", " ", "rows", " ", "specified", " ", "by",
               " ", 
              RowBox[{
               StyleBox["dropspec",
                FontSlant->"Italic"], ".", "\[IndentingNewLine]", 
               "Delete"}], " ", "any", " ", "rows", " ", "for", " ", 
              "which", " ", 
              StyleBox["distance", "Program"]}], " ", "<", " ", 
             StyleBox["minDistance",
              FontSlant->"Italic"]}], ";", " ", 
            RowBox[{
            "if", " ", "no", " ", "rows", " ", "are", " ", "deleted"}]}], 
           ",", "\[IndentingNewLine]", "   ", 
           RowBox[{
           "return", " ", "the", " ", "first", " ", "two", " ", "columns",
             " ", "of", " ", "fakedata"}], ",", " ", 
           RowBox[{"ignoring", " ", 
            RowBox[{"dropspec", "."}]}]}], 
          StyleBox[" ",
           FontSlant->"Italic"], "*)"}], "\[IndentingNewLine]", 
         RowBox[{
          RowBox[{"func1", "[", "dropspec_", "]"}], ":=", 
          RowBox[{"Module", "[", 
           RowBox[{
            RowBox[{"{", 
             RowBox[{"part", ",", "fake"}], "}"}], ",", 
            "\[IndentingNewLine]", 
            RowBox[{
             RowBox[{"part", "=", 
              RowBox[{"fakedata", "\[LeftDoubleBracket]", 
               RowBox[{"All", ",", 
                RowBox[{"{", 
                 RowBox[{"1", ",", "2"}], "}"}]}], 
               "\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]", 
             RowBox[{"fake", "=", 
              RowBox[{"part", "~", "Drop", "~", "dropspec"}]}], ";", 
             "\[IndentingNewLine]", 
             RowBox[{
              RowBox[{
               RowBox[{"If", "[", 
                RowBox[{
                 RowBox[{"#", "=!=", 
                  RowBox[{"{", "}"}]}], ",", 
                 RowBox[{"fake", "~", "Delete", "~", "#"}], ",", "part"}],
                 "]"}], "&"}], "@", "\[IndentingNewLine]", 
              RowBox[{"Position", "[", 
               RowBox[{
                RowBox[{"distance", "/@", "fake"}], ",", 
                RowBox[{"x_", "/;", 
                 RowBox[{"x", "<", "minDistance"}]}]}], "]"}]}]}]}], 
           "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
         RowBox[{"If", "[", 
          RowBox[{
           RowBox[{"num", "=!=", 
            RowBox[{"{", "}"}]}], ",", 
           RowBox[{"func1", " ", "@", " ", 
            RowBox[{"num", "\[LeftDoubleBracket]", 
             RowBox[{
              RowBox[{"-", "1"}], ",", "1"}], "\[RightDoubleBracket]"}]}],
            ",", 
           RowBox[{"func1", "@", "0"}]}], "]"}]}]}], " ", 
       "]"}]}]], "Input"]
    }, Open  ]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been developing my own PHP MVC framework. Now I have seen different
I'm getting the following error: javax.servlet.jsp.JspException: Broken pipe Now I have seen questions/answers with
What does the Linux /proc/meminfo Mapped topic mean? I have seen several one-liners that
We have a piece of functionality that is used by several different applications (clients)
I've seen a couple similar threads to this question, but none of them really
There are a few should I chose this or that questions on SO and
I have been getting a number of attacks on my website lately, with a
I'm a newbie when it comes to LINQ... I have an IEnumerable generic list
I've never quite understood how the argument lists for operator overloading are determined in
I am very new to Flex (started learning a couple of days back), I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.