Method is too long ?????

  • 100

If you have a common divider (chr(13)) then this will be faster, easier to read and a whole lot less typing.

Dim result, text() as string

text.append “your line goes here”
text.append “your line goes here”
text.append “your line goes here”

result = Join(text,chr(13))

OK, didn’t know that.

I am going to follow Daves advice and use a string area. Thats the easiest way for now.

Seriously take a stab at breaking that one very long method into several that each do bits of work
Long term it will make you code easier to maintain and you’re much less likely to run into surprises like this

[quote=122906:@Norman Palardy]Seriously take a stab at breaking that one very long method into several that each do bits of work
Long term it will make you code easier to maintain and you’re much less likely to run into surprises like this[/quote]

To start with, would it not be cleaner to do the concatenation thing in a separate method ? That way temporary variables would be cleaned upon return, right ?

I’ve seen this code once before attached to a bug report
It could be refactored into several smaller chunks and this problem would not exist

See <https://xojo.com/issue/9341>

[quote=122911:@Norman Palardy]I’ve seen this code once before attached to a bug report
It could be refactored into several smaller chunks and this problem would not exist[/quote]

No Norman, you did not see this method before. The one you saw could (and is now) be splitter into smaller pieces.

Here is a snipped of the code of a method that write some presets to a file.
There are about 700 preset options. So in total about 1400 lines of code.
It would not make sense to split this method. It would only make it harder to read.

[code] dim line as string

line = line + “EncodePreset “+batchlist(batchID).EncodePreset+””+chr(13)
line = line + " "+chr(13)

line = line + “EncodePresetName “+batchlist(batchID).EncodePresetName+””+chr(13)
line = line + " "+chr(13)

line = line + “EncodePresetMenuCheckedNumber “+str(batchlist(batchID).EncodePresetMenuCheckedNumber)+””+chr(13)
line = line + " "+chr(13)

line = line + “EncodePresetSubCheckedNumber1 “+str(batchlist(batchID).EncodePresetSubCheckedNumber1)+””+chr(13)
line = line + " "+chr(13)

line = line + “EncodePresetSubCheckedNumber2 “+str(batchlist(batchID).EncodePresetSubCheckedNumber2)+””+chr(13)
line = line + " "+chr(13)

line = line + “EncodePresetSubCheckedNumber3 “+str(batchlist(batchID).EncodePresetSubCheckedNumber3)+””+chr(13)
line = line + " "+chr(13)

… CUT some same text as above

line = line + “EncodePresetSubCheckedNumber3 “+str(batchlist(batchID).EncodePresetSubCheckedNumber3)+””+chr(13)
line = line + " "+chr(13)

dim fs as folderitem
dim ts as textOutputStream
fs = SpecialFolder.ApplicationData.child(“presetsFolder”).child(presetfile)

if fs <> nil then
  ts = TextOutputStream.create(fs)
  ts.writeLine(line)
  ts.close
end if

return true[/code]

Anyhow, I now use an array and it is working fine.

[quote=122939:@Christoph De Vocht]No Norman, you did not see this method before. The one you saw could (and is now) be splitter into smaller pieces.
[/quote]
I assumed this was all part of that same gigantic method
I’d still split this into smaller chunks